如何在没有括号,逗号的情况下创建列表,并让每个元素都以新行开头?

时间:2016-05-26 15:56:57

标签: python python-3.x

我有一个创建句子列表的循环,我希望它们像这样打印(所有在不同的行上):

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)

1 个答案:

答案 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