[英]How to choose a integer number with the function random in python?
我有一个数字列表,我想从该列表中选择一个带有 random() 的随机数,以便我可以在循环函数中使用它,但是即使我写下所选的随机数是一个整数。
You should start by importing random .您应该从导入random开始。
So it should like something like this eg所以它应该像这样的东西,例如
import random
myList = ['a', 'b', 'c', 'd', 'e']
print(random.choice(myList))
Then it will print out a random number from your list.然后它会从您的列表中打印出一个随机数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.