Important Notice:

Course Content
The Calendar Module
Library Function/Predefined Functions
0/4
Sys Module
Library Function/Predefined Functions
0/2
OS Module
Library Function/Predefined Functions
0/2
Functions in Python (Chapter-10) M3-R5
About Lesson

shuffle() Method

               The shuffle() method takes a sequence, like a list, and reorganize the order of the items.

Note: This method changes the original list, it does not return a new list.

Syntax

random.shuffle(sequence)

Parameter Values

Parameter

Description

sequence

Required. A sequence.

function

Deprecated since Python 3.9. Removed in Python 3.11.
Optional. The name of a function that returns a number between 0.0 and 1.0.
If not specified, the function random() will be used

 Example

Shuffle a list (reorganize the order of the list items):

import random
mylist = [“apple”, “banana”, “cherry”]
random.shuffle(mylist)
print(mylist)

Output:

[“apple”, “cherry”, “banana”]

error: Content is protected !!