« Python modules

random


get a random item from a python list
import random # Define a new list using [] square brackets. fruits = ['banana', 'apple', 'orange', 'lemon', 'lime', 'strawberry', 'kiwi', 'peach', 'grape', 'pineapple', 'mango'] # Randomly select an item from a list print('=== Get a random item ===') print(random.choice(fruits)) # output run 1 === Get a random item === lime # output run 2 === Get a random item === pineapple # output run 3 === Get a random item === kiwi Read More →