我有一个创建句子列表的循环,我希望它们像这样打印(所有在不同的行上):
Hi my name is joe
Hi my name is Sally
Hi my name is Bert
但他们正在这样打印:
['Hi my name is joe', 'Hi my name is Sally', 'Hi my name is Bert']
我对python不太好,所以我想要一个简单的答案。我的循环看起来有点像这样:
sentence = "Hi my name is " + random.choice(name)
if name not in list:
list.append(sentence)
答案 0 :(得分:2)
如果您的列表是这样的:
list = ['Hi my name is joe', 'Hi my name is Sally', 'Hi my name is Bert']
然后你就可以这样做:
for a in list: print(a)
哪会输出这个:
Hi my name is joe
Hi my name is Sally
Hi my name is Bert