Python Basics
Python Advanced
Python Useful References
Python Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Python Number choice() Function
Description:
This function returns a random item from a list, tuple, or string.
Syntax:
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.
Parameters:
Here is the detail of parameters:
Return Value:
A random item
Example:
#!/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
|
|
|
|