Articles → Python → Random functions in python

Random functions in python






Random functions













Choice




import random

fruits = ["Apple", "Orange", "Banana", "Grapes", "Strawberry"]

print (random.choice(fruits))





Click to Enlarge


Shuffle




import random


fruits = ["Apple", "Orange", "Banana", "Grapes", "Strawberry"]


print (fruits)

random.shuffle(fruits)

print (fruits)





Click to Enlarge


randrange




import random

print (random.randrange(1,10))





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, February 19, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250