pythonrandom

How to make python choose randomly between multiple strings?


How to make python choose randomly between multiple strings?


Solution

  • Add them all to a list, import random, then call the choice method like so:

    In [1]: import random
    In [2]: hello = ['hi', 'hello', 'yo', 'bonjour', 'hola', 'salaam']
    In [3]: random.choice(hello)
    Out[3]: 'bonjour'