1 注释:写注释是为了帮助理解代码里面比较难得一部分内容,不是没一行代码都需要写注释
2 字符串创建:单引号双引号都可以,但在python中,比较短的字符串的创建一般用单引号
3 代码:
print("Mary had a little lamb.") # 输出“玛丽有一只小羊羔” print("Its fleece was white as {}.".format('snow')) # 输出“它的羊毛洁白如雪” print("And everywhere that Mary went.") # 输出“玛丽去过的每一个地方” print("." * 10) # what that do? 字符“.”被输出了10次,表示省略号 end1 = "c" # 定义了一个字符串变量“end1”,它的值是字符“c” end2 = "h" end3 = "e" end4 = "e" end5 = "s" end6 = "e" end7 = "B" end8 = "u" end9 = "r" end10 = "g" end11 = "e" end12 = "r" # watch that comma at the end. try removing it to see what h print(end1 + end2 + end3 + end4 + end5 + end6,end='') # 输出一个字符串cheese芝士 print(end7 + end8 + end9 + end10 + end11 +end12) # 输出一个字符串Burger汉堡
4 运行结果
PS E:3_work4_python2_code 2_LearnPythonTheHardWay> python ex7.py
Mary had a little lamb.
Its fleece was white as snow.
And everywhere that Mary went.
..........
cheeseBurger