Copyright © tutorialspoint.com
This function returns a random item from a list, tuple, or string.
choice( seq ) |
Note: This function is not accessible directly so we need to import random module and then we need to call this function using random static object.
Here is the detail of parameters:
seq: This could be a list, tuple, or string..
A random item
#!/usr/bin/python import random print "choice([1, 2, 3, 5, 9]) : ", random.choice([1, 2, 3, 5, 9]) print "choice('A String') : ", random.choice('A String') |
This will produce following result:
choice([1, 2, 3, 5, 9]) : 2 choice('A String') : n |
Copyright © tutorialspoint.com