Python3 shuffle() Function
Description
shuffle() The method randomly shuffles all elements of a sequence.
Syntax
The syntax of the shuffle() method is as follows:
import
random
random
.
shuffle
(
lst
)
**Note:** shuffle() cannot be accessed directly; you need to import the random module and call the method through the static random object.
Parameters
- lst -- a list.
Return Value
Returns None.
Example
The following shows examples of using the shuffle() method:
Example
#!/usr/bin/python3
import
random
list
=
[
20
,
16
,
10
,
5
]
;
random
.
shuffle
(
list
)
(
"
Randomly sorted list:
"
,
list
)
random
.
shuffle
(
list
)
(
"
Randomly sorted list:
"
,
list
)
Running the example above produces:
随机排序列表 : [20, 5, 16, 10]
随机排序列表 : [5, 20, 10, 16]
Python3 Numbers