def question():
question1 = [
"what is you name?:\n Where do you live? :"
]
print(question1)
question()
\n
没有中断。如果我不使用函数\n
起作用(将文本放入下一行),但我需要将其放在函数内,请有人帮我。
question1
是Python列表,因此print(question1)
正在打印列表的字符串表示,它不会在换行符处中断,而是在输出中显示换行符,如您所见:['what is you name?:\n Where do you live? :']
另一方面,如果您是print(question[0])
,则由于要打印原始字符串,您将获得所需的结果:
what is you name?: Where do you live? :
list
(question1
是list
对象),而不是str
。如果要在数组中打印该字符串,请像这样对它进行索引question1 = [
"what is you name?:\n Where do you live? :"
]
# question1[0] means "first element of question1"
print(question1[0])
您还真的需要list
吗?为什么不在这里直接使用字符串?像这样
question1 = "what is you name?:\n Where do you live? :" print(question1)