Home >>Python Random Module >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 | 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. |
import random
mycolor = ["red", "green", "blue"]
random.shuffle(mycolor)
print(mycolor)
import random
def myfunction():
return 0.5
myNum = ["20", "56", "89"]
random.shuffle(myNum, myfunction)
print(myNum)