欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

笨办法09打印,打印,打印

程序员文章站 2022-06-15 18:44:38
...
# Here's some new strange stuff, remember type it exactly.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\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."
"""

输出结果:
笨办法09打印,打印,打印

代码中:\n 表示回车换行,此处\n后若加空格,则换行字符也会空出一格,显示如下:
笨办法09打印,打印,打印


加入几个\n看一下作用:

print """
There's something going on here.\nWith the three double-quotes.\n
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6."
"""

打印结果如下:
笨办法09打印,打印,打印


若最后一段想使用双引号,可以这么写:在每行最后加上“\”,就是没啥必要╮(╯_╰)╭:

print "There\'s something going on here.\
\nWith the three double-quotes.\
\nWe\'ll be able to type as much as we like.\
\nEven 4 lines if we want, or 5, or 6."

输出结果与使用三个双引号相同
笨办法09打印,打印,打印