Python2:
# Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed Thu Fri Sat Sun" months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug" print "Here are the days: ", days print "Here are the months: ", months print """ There's something going on here. With the three double-quotes. We'll be able to type as much as we like. Even 4 lines if we want, or 5, or 6. """
你应该看到的结果:
Python3代码:
# Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed Thu Fri Sat Sun" months = "Jan\nFed\nMar\nApr\nMay\nJun\nJul\nAug" print ("Here are the days: ", days) print ("Here are the months: ", months) print (""" There's something going on here. With the three double-quotes. We'll be able to type as much as we like. Even 4 lines if we want, or 5, or 6. """)
输出结果为:
这里说一下"\"的意义:换行,\是转义的意思,'\n'是换行,'\t'是tab,'\\'是\
例如:
text = "abc"+"\n"+"123"+"\t"+"xyz"+"\\" print (text)
输出结果为
加分习题
1. 自己检查结果,记录你犯过的错误,并且在下个练习中尽量不犯同样的错误。