Sunday, March 4, 2018

Number choice() method


Number choice() Method in Python 3:

Description
The choice() method returns a random item from a list, tuple, or string.
Syntax
Following is the syntax for choice() method
import random
choice( seq )

Note: This function is not accessible directly, so we need to import the random module and then we need to call this function using the random static object.

Parameters
          seq - This could be a list, tuple, or string...

Return Value
       This method returns a random item.
Example
The following example shows the usage of the choice() method.


When we run the above program, it produces a result similar to the following