Code Explanation:
Step 1: Importing the random Module
import random
The random module in Python provides functions for generating random numbers and performing random operations.
Step 2: Creating a List
data = [1, 2, 3]
A list named data is created containing the elements [1, 2, 3].
Step 3: Shuffling the List
random.shuffle(data)
The random.shuffle() function randomly rearranges the elements of the list data in place.
Since shuffling is random, the order of elements will change each time the program runs.
Step 4: Printing the Shuffled List
print(data)
This prints the shuffled version of data after random.shuffle() is applied.
0 Comments:
Post a Comment