Skip to main content
randrange assumes 0 if you don't pass it, also use python3 print statement and added link to documentation
Source Link

In caseIf you also need the index:, use random.randrange

foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
print (foo[random_index])

In case you also need the index:

foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
print foo[random_index]

If you also need the index, use random.randrange

from random import randrange
random_index = randrange(len(foo))
print(foo[random_index])
I rephrased a sentence so it became clearer why I was suggesting this approach.
Source Link

A more general approachIn case you also need the index:

foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
print foo[random_index]

A more general approach:

foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
print foo[random_index]

In case you also need the index:

foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
print foo[random_index]
Source Link

A more general approach:

foo = ['a', 'b', 'c', 'd', 'e']
from random import randrange
random_index = randrange(0,len(foo))
print foo[random_index]