Python choice() function
Description
choice() The method returns a random item from a list, tuple, or string.
Syntax
The syntax of the choice() method is as follows:
import random
random.choice( seq )
**Note:** choice() cannot be accessed directly; you need to import the random module and call the method through the static random object.
Parameters
- seq -- can be a list, tuple, or string.
Return Value
Returns a random item.
Example
The following shows examples of using the choice() method:
#!/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')
Running the example above produces:
choice([1, 2, 3, 5, 9]) : 2
choice('A String') : n
Python Numbers