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

相关文章
|
1月前
|
Python
Python:函数篇(每周练习)
Python:函数篇(每周练习)
81 1
|
2月前
|
机器学习/深度学习 人工智能 算法
【Python】编程练习的解密与实战(一)
【Python】编程练习的解密与实战(一)
37 0
|
4月前
|
算法 Python
Python实战练习示例
Python实战练习示例
43 7
|
7月前
|
iOS开发 Python
Python流程控制语句-条件判断语句练习及应用详解
Python流程控制语句-条件判断语句练习及应用详解
94 0
|
8天前
|
索引 Python
python 格式化、set类型和class类基础知识练习(上)
python 格式化、set类型和class类基础知识练习
32 0
|
2月前
|
Python
Python猜字游戏是一种常见的编程练习
Python猜字游戏是一种常见的编程练习
24 2
|
2月前
|
机器学习/深度学习 人工智能 算法
【Python】编程练习的解密与实战(四)
【Python】编程练习的解密与实战(四)
38 0
|
2月前
|
机器学习/深度学习 人工智能 算法
【Python】编程练习的解密与实战(二)
【Python】编程练习的解密与实战(二)
50 0
|
3月前
|
算法 小程序 搜索推荐
python一百道经典基础练习题目
python一百道经典基础练习题目
58 1
|
8月前
|
NoSQL Python
牛客网Python入门103题练习|【08--元组】
牛客网Python入门103题练习|【08--元组】
125 1

热门文章

最新文章