select random string in python code example

Example 1: choose random index from list python

import random  # Don't forget to install it first with pip install random

ahahfunny = ['ahah ', 'copy-', 'paste ', 'stack overflow',' go ', 'brrr']
#  the biggest index in this list above is 5 (0 being 1 in programming)

print(ahahfunny[random.randint(0, 5)]  # I like this way,
      
print(random.choice(ahahfunny)) # But this way is WAY thiccer...

Example 2: random string generate python of 2.7

>>> import string
>>> import random
>>> def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))