比方说:
list=["A","B","C"]
listitem = random.randint(0,2)
我输入:
print listitem
但是它给出了一个数字,而我想要一封信?
我该怎么做?
最佳答案
您可以使用随机
:
>>> from random import choice
>>> List = [ 'A','B','C' ]
>>> choice( List )
C
>>> choice( List )
A
>>> choice( List )
B
关于python - 如何从列表中打印随机值名称?(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11574029/