python学习笔记 怎么换行输出多个变量?
-
学习廖雪峰的教程时做练习时遇到的问题
我想把变量换行依次输出
我的错误代码:>>> n=123 >>> f=456.789 >>> s1='hello,world' >>> s2='hello,\'adam\'' >>> s3=r'hello,"bart"' >>> s4=r'''hello, ... lisa!''' >>> print(n\nf\ns1\ns2\ns3\ns4\n) File "<stdin>", line 1 print(n\nf\ns1\ns2\ns3\ns4\n) ^ SyntaxError: unexpected character after line continuation character
还错了很多次
>>> print(s1'\n's2'\n') File "<stdin>", line 1 print(s1'\n's2'\n') ^ SyntaxError: invalid syntax >>> print("\n123\n456\n789") 123 456 789 >>> print(s1"\n"s2"\n") File "<stdin>", line 1 print(s1"\n"s2"\n") ^ SyntaxError: invalid syntax
百度的结果
>>> print(s1,s2,s3,s4,sep='\n') hello,world hello,'adam' hello,"bart" hello, lisa!
完美!