首页 > 程序开发 > Web开发 > Python >

Learn Python The Hard Way学习(7) - 更多的打印

2012-06-21

下面会做更多的练习,自己动手敲代码并且运行起来,不要复制粘贴,或者跳个这些练习。1.# -- coding: utf-8 --2.print "Mary had a little lamb."3.print "Its fleece was white as %s." % &#3...

下面会做更多的练习,自己动手敲代码并且运行起来,不要复制粘贴,或者跳个这些练习。
1. # -- coding: utf-8 --
2. print "Mary had a little lamb."
3. print "Its fleece was white as %s." % 'snow'
4. print "And everywhere that Mary went."
5. print "," * 10 # 这里做了什么?
6.
7.
8. end1 = "C"
9. end2 = "h"
10. end3 = "e"
11. end4 = "e"
12. end5 = "s"
13. end6 = "e"
14. end7 = "B"
15. end8 = "u"
16. end9 = "r"
17. end10 = "g"
18. end11 = "e"
19. end12 = "r"
20.
21.
22. # 看看后面的逗号,去掉的话看看会发生什么
23. print end1 + end2 + end3 + end4 + end5 + end6,
24. print end7 + end8 + end9 + end10 + end11 + end12

运行结果
Mary had a little lamb.
Its fleece was white as snow.
And everywhere that Mary went.
,,,,,,,,,,
Cheese Burger

加分练习
接下来的几个练习的加分练习是一样的。
1. 为每行写注释
2. 认真阅读你的代码,找出错误。
3. 从现在开始记录你的错误,写在纸上。
4. 进行下一个练习的时候看一下自己的错误,避免再犯。
5. 程序员和魔术师一样希望自己从不犯错,但是那是不可能的,每个人都会犯错。

下面会做更多的练习,自己动手敲代码并且运行起来,不要复制粘贴,或者跳个这些练习。
1. # -- coding: utf-8 --
2. print "Mary had a little lamb."
3. print "Its fleece was white as %s." % 'snow'
4. print "And everywhere that Mary went."
5. print "," * 10 # 这里做了什么?
6.
7.
8. end1 = "C"
9. end2 = "h"
10. end3 = "e"
11. end4 = "e"
12. end5 = "s"
13. end6 = "e"
14. end7 = "B"
15. end8 = "u"
16. end9 = "r"
17. end10 = "g"
18. end11 = "e"
19. end12 = "r"
20. www.2cto.com
21.
22. # 看看后面的逗号,去掉的话看看会发生什么
23. print end1 + end2 + end3 + end4 + end5 + end6,
24. print end7 + end8 + end9 + end10 + end11 + end12

运行结果
Mary had a little lamb.
Its fleece was white as snow.
And everywhere that Mary went.
,,,,,,,,,,
Cheese Burger

加分练习
接下来的几个练习的加分练习是一样的。
1. 为每行写注释
2. 认真阅读你的代码,找出错误。
3. 从现在开始记录你的错误,写在纸上。
4. 进行下一个练习的时候看一下自己的错误,避免再犯。
5. 程序员和魔术师一样希望自己从不犯错,但是那是不可能的,每个人都会犯错。

作者:lixiang0522

相关文章
最新文章
热点推荐