Import random | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Import random

How to choose one random item in Python between multiple strings? random.randint is for numbers random._______ is for String???

28th Mar 2020, 6:52 AM
Ali Khosroanjam
Ali Khosroanjam - avatar
4 Answers
+ 4
random.choice(iterable) will return a random item from the iterable. if your strings are in an iterable, it should work.
28th Mar 2020, 6:57 AM
John Robotane
John Robotane - avatar
what do you mean by multiple string?
28th Mar 2020, 6:56 AM
Muhammad Faheem Nasir
Muhammad Faheem Nasir - avatar
2 or 3 or ... string Thanks very much🙌🙌🙌
28th Mar 2020, 7:02 AM
Ali Khosroanjam
Ali Khosroanjam - avatar
Are you trying to return a random character from a string or return a random word from a sentence/phrase?
28th Mar 2020, 8:20 AM
rodwynnejones - avatar