Easy Tutorial
❮ Ref Set Copy Python String Rindex ❯

Python3 shuffle() Function

Python3 Numbers


Description

The shuffle() method randomly shuffles all the elements of a sequence.


Syntax

Here is the syntax for the shuffle() method:

import random

random.shuffle(lst)

Note: shuffle() cannot be accessed directly; it requires importing the random module and then calling this method via the random static object.


Parameters


Return Value

Returns None.


Example

The following demonstrates the use of the shuffle() method:

#!/usr/bin/python3
import random

list = [20, 16, 10, 5];
random.shuffle(list)
print("Shuffled list : ", list)

random.shuffle(list)
print("Shuffled list : ", list)

The output of the above example is:

Shuffled list :  [20, 5, 16, 10]
Shuffled list :  [5, 20, 10, 16]

Python3 Numbers

❮ Ref Set Copy Python String Rindex ❯