练习7--打印打印

1 注释:写注释是为了帮助理解代码里面比较难得一部分内容,不是没一行代码都需要写注释

2 字符串创建:单引号双引号都可以,但在python中,比较短的字符串的创建一般用单引号

3 代码:

  1. print("Mary had a little lamb.") # 输出“玛丽有一只小羊羔”
  2. print("Its fleece was white as {}.".format('snow')) # 输出“它的羊毛洁白如雪”
  3. print("And everywhere that Mary went.") # 输出“玛丽去过的每一个地方”
  4. print("." * 10) # what that do? 字符“.”被输出了10次,表示省略号
  5. end1 = "c" # 定义了一个字符串变量“end1”,它的值是字符“c”
  6. end2 = "h"
  7. end3 = "e"
  8. end4 = "e"
  9. end5 = "s"
  10. end6 = "e"
  11. end7 = "B"
  12. end8 = "u"
  13. end9 = "r"
  14. end10 = "g"
  15. end11 = "e"
  16. end12 = "r"
  17. # watch that comma at the end. try removing it to see what h
  18. print(end1 + end2 + end3 + end4 + end5 + end6,end='') # 输出一个字符串cheese芝士
  19. print(end7 + end8 + end9 + end10 + end11 +end12) # 输出一个字符串Burger汉堡

4 运行结果

  • PS E:\3_work\4_python\2_code\02_LearnPythonTheHardWay> python ex7.py
  • Mary had a little lamb.
  • Its fleece was white as snow.
  • And everywhere that Mary went.
  • ..........
  • cheeseBurger

猜你喜欢

转载自www.cnblogs.com/luoxun/p/13166682.html
今日推荐