How to assign random values(words) from a string to a variable in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to assign random values(words) from a string to a variable in Python?

How to assign random values(words) from a string to a variable in Python?

25th Jan 2020, 8:36 PM
xAlexMinecraft
xAlexMinecraft - avatar
3 Answers
+ 4
You can make a list and then use the choices method from the random module to get a random value from that list
25th Jan 2020, 8:46 PM
‎‫omri
‎‫omri - avatar
+ 4
Use the spilt() method on a string inside a random.choice() function.
25th Jan 2020, 8:48 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Thanks!
25th Jan 2020, 8:52 PM
xAlexMinecraft
xAlexMinecraft - avatar