Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在前缀中生成所有可能的数字:
import random prefix = "05" print prefix + #all Possible Numbers Here
你的意思是你如何生成一个随机数并在它前面加上一个给定的字符串?以您的代码为例,您可以这样做:
import random prefix = '05' print prefix + str(random.randrange(1, 100)
这将选择 1 到 100 之间的随机整数,因此您可以进行相应调整。对于随机非整数,将其替换为random.random().
random.random()