天天看點

LearnPython3theHardWay__Excercise 7 More Printing

知識點:字元串也有“加法和乘法”和print(i,end=’’)的使用

更多的練習,是為了打好基礎。開始吧!不要懶惰!不要複制粘貼!

在這節練習,我們複習了 {}.format() 和字元串的“加法”(第20、21行),新接觸了字元串的“乘法”(第4行)和第20行的print( i , end=’ ')

print("Mary had a little lamb.")
print("Its fleece was white as {}".format('snow'))
print("And everywhere that Mary went.")
print("." * 10)  # what'd that do? 字元串的乘法是輸出10次的意思

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 end = ' ' at the end. try removing it to see what happens
print(end1 + end2 + end3 + end4 + end5 + end6, end=' ')
print(end7 + end8 + end9 + end10 + end11 + end12)

           

print( i , end=’ ') ==>引号裡是一個空格,意思是輸入i後,以空格結尾。本來預設是換行。如果去掉end,則顯示如下結果

Cheese
Burger
           
What you should see
Mary had a little lamb.
Its fleece was white as snow
And everywhere that Mary went.
..........
Cheese Burger

           
Study Drills

1、 注釋每一行

2、 仔細看或讀每一行,找出你的錯誤

3、 從現在起,當你出錯了,在紙上寫你犯了什麼類型的錯誤

4、 當你要做下一個練習前,看看你犯過的錯誤,盡量不要再犯

5、 每個人都會犯錯。程式員經常犯錯。