用Notepad++打下列的程式碼,
另存為ex7.py.
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? 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 happens print (end1 + end2 + end3 + end4 + end5 + end6, end = " ") print (end7 + end8 + end9 + end10 + end11 + end12)然後用Windows的cmd, 執行python打開它.
C:\Windows\System32>cd C:\Users\Peter\Desktop\Python\LP3THW C:\Users\Peter\Desktop\Python\LP3THW>python .\ex7.py Mary had a little lamb. Its fleece was white as snow. And everywhere that Mary went. .......... Cheese Burger C:\Users\Peter\Desktop\Python\LP3THW>完成
這次練習主要是學習把一個字串放進另外一個字串.
Line 3 - 4, 我用另外一種方式表達出來跟上面相同的結果.
Line 6, 主要是學習將字符"@"連續乘10次
Line 22, 主要是學習接著打印在同一行.我將之修改為"_"
print ("Mary had a little lamb.") print ("Its fleece was white as {}.".format("snow")) SNOW = "snow" print (f"Its fleece was white as {SNOW}.") print ("And everywhere that Mary went.") print ("@" * 10) # what'd that do? 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 happens print (end1 + end2 + end3 + end4 + end5 + end6, end = '_') print (end7 + end8 + end9 + end10 + end11 + end12)
結果,
C:\Users\Peter\Desktop\Python\LP3THW>python .\ex7.py Mary had a little lamb. Its fleece was white as snow. Its fleece was white as snow. And everywhere that Mary went. @@@@@@@@@@ Cheese_Burger C:\Users\Peter\Desktop\Python\LP3THW>Line 3 & 4, 是相同的結果. 這是我用另外一種方式表達.
最初發表 / 最後更新: 2018.08.01 / 2018.08.01
0 comments:
張貼留言