Latest web development tutorials

Python shuffle () function

Python figures Python figures


description

All elementsshuffle () method of randomly ordered sequence.


grammar

The following is the syntax shuffle () method:

import random

random.shuffle (lst )

Note: shuffle () is not directly accessible, you need to import the random module, and then call the method by random static objects.


parameter

  • lst - can be a sequence or tuple.

return value

Returns a random sequence sorted.


Examples

The following shows an example of using the shuffle () method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import random

list = [20, 16, 10, 5];
random.shuffle(list)
print "随机排序列表 : ",  list

random.shuffle(list)
print "随机排序列表 : ",  list

After running the above example output is:

随机排序列表 :  [16, 5, 10, 20]
随机排序列表 :  [16, 5, 20, 10]

Python figures Python figures