vendredi 11 août 2017

How do I make random.choice include not-choosing?

I try to select an item in a list randomly or not to choose anything.

For example, I want to choose 'a', or 'b', or blank(none of them). Is there any way to do this? Or should I just make random.choice('a','b','') and pop this('') out?

import random

foo = ['a', 'b'] print(random.choice(foo))

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire