Home >>Python Random Module >Python Random shuffle() Method

Python Random shuffle() Method

Python Random shuffle() Method

Python Random shuffle() Method in python randomizes a sequence of a list, tuple, or string in a place.

Syntax:
random.shuffle(sequence, function)

Parameter Values

Parameter Description
Sequence It is Required a list, a tuple, or a string in a sequence.
Function It is Optional. A function name which returns a number between 0.0 and 1.0.
Here is an example of Python Random shuffle() Method:

import random
mycolor = ["red", "green", "blue"]
random.shuffle(mycolor)
print(mycolor)

Output:
['red', 'blue', 'green']
Example 2:

import random
def myfunction():
return 0.5
myNum = ["20", "56", "89"]
random.shuffle(myNum, myfunction)
print(myNum)

Output:
['20', '89', '56']