笨办法学 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. 自己检查结果,记录你犯过的错误,并且在下个练习中尽量不犯同样的错误。

相关文章
|
7天前
|
Python
Python 练习实例15
Python 练习实例15
|
4天前
|
Python
Python 练习实例18
Python 练习实例18
|
4天前
|
Python
Python 练习实例16
Python 练习实例16
|
1天前
|
Python
Python 练习实例30
Python 练习实例30
|
1天前
|
Python
Python 练习实例29
Python 练习实例29
|
7天前
|
Python
Python 练习实例14
Python 练习实例14
|
4天前
|
Python
Python 练习实例19
Python 练习实例19
|
2天前
|
Python
Python 练习实例27
Python 练习实例27
|
2天前
|
Python
Python 练习实例26
Python 练习实例26
|
2天前
|
Python
Python 练习实例25
Python 练习实例25