titleList=[['a','b','c'],['1','2','3'],['x','y','z']] word=[] for i in range(10): for t in titleList: word.append(random.choice(t)) title=''.join(word) print(title)
我希望组合出来的字符是随机的,为什么出来是一样的呢?谢谢了,帮我找一下问题。
因为你的word数组变量是全局的,你应该修改为局部变量
word
titleList=[['a','b','c'],['1','2','3'],['x','y','z']] for i in range(10): word=[] for t in titleList: word.append(random.choice(t)) title=''.join(word) print(title)
1.4m articles
1.4m replys
5 comments
57.0k users