笨办法学 Python--跟书练习九~打印 打印 打印

简介: 笨办法学 Python--跟书练习九~打印 打印 打印

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.
"""


你应该看到的结果:

640.png


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.
""")


输出结果为:

640.png

这里说一下"\"的意义:换行,\是转义的意思,'\n'是换行,'\t'是tab,'\\'是\

例如:


text = "abc"+"\n"+"123"+"\t"+"xyz"+"\\"
print (text)


输出结果为


640.png

加分习题


1. 自己检查结果,记录你犯过的错误,并且在下个练习中尽量不犯同样的错误。

相关文章
|
6月前
|
Python
Python 练习实例26
Python 练习实例26
|
6月前
|
Python
Python 练习实例25
Python 练习实例25
|
5月前
|
Python
Python推导式:小练习
Python推导式:小练习
|
5月前
|
Python
Python 练习实例35
Python 练习实例35
|
5月前
|
Python
Python 练习实例34
Python 练习实例34
|
6月前
|
Python
Python 练习实例33
Python 练习实例33
|
5月前
|
Python
Python 练习实例36
Python 练习实例36
|
6月前
|
Python
Python 练习实例30
Python 练习实例30
|
6月前
|
Python
Python 练习实例29
Python 练习实例29
|
6月前
|
Python
Python 练习实例21
Python 练习实例21

热门文章

最新文章