+ 3
Hellow every one! I would like if someone will teach me how to pick a random string/integer from a list, in python3
how to use the random method for pick a random str/int from list in python3?
7 Antworten
+ 8
#Toni's code doing random length from the list.
#If you want to get random value from the list, you need to use choice.
from random import choice
nums = [1,2,3,4,5]
rand = choice(nums)
print(rand)
# Or without variable
print(choice(nums))
+ 4
you right, thank you
+ 4
You need only change content from list to that you wrote with "g","h" and what more you want.
+ 3
from random import randint
list = [1, 2 3, 4, 5];
result = list[randint(0, len(list) - 1)]
+ 3
thank you very much
+ 3
can you create a code for example? make a list with string like "h","g" and then make python choose one of them thank you!
+ 3
just like:
'from random import choise
list=["g","h"]
print (choise(list))?