randomUse the module
If you want to pick an item right away, choose()
import random
a = [1,2,3,4,5,6,7,8,9,10]
print random.choice(a)
If you need a random index, landrange()
import random
a = [1,2,3,4,5,6,7,8,9,10]
randomIndex = random.randrange(0,len(a))
print a[randomIndex]
Try it with me
© 2024 OneMinuteCode. All rights reserved.