天天看點

《笨辦法學python3-Learn Python 3 the HARD WAY》-習題9 列印,列印,列印

學習内容:

# Here's some new strange stuff, remember type it exactly.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFen\nMar\nApr\nMay\nJun\nJul\nAug"

print ("Here sre the days:", days)
print ("Here are the months:",months)

print ("""
There's something going on here.
With the three double-quotes.
We'll be able to type as muchas we like.
Even 4 line if wu want, or 5, or 6.
""")
           

運作結果:

《笨辦法學python3-Learn Python 3 the HARD WAY》-習題9 列印,列印,列印

知識點:

  1. 換行符

    \n:換行符

    例:字元串後面跟着\n 就是下一個字元串換行的意思。

months = "Jan\nFen\nMar\nApr\nMay\nJun\nJul\nAug"
print (months)
           
《笨辦法學python3-Learn Python 3 the HARD WAY》-習題9 列印,列印,列印

2. 多行注釋符

“”“字元串内容”"" :主要展現在跨行的字元串上,會包含兩個界定符号之間的所有字元,包括看得見和看不見的,例如回車換行等。

可以了解為在三個引号之間的字元串你是怎麼輸入的,列印時就如何輸出,減少了\n這類的換行符。

注:兩頭的三個引号之間不能有空格。

例:

print ("""
    There's something going on here.
        With the three double-quotes.
            We'll be able to type as muchas we like.
                Even 4 line if wu want, or 5, or 6.
""")
           
《笨辦法學python3-Learn Python 3 the HARD WAY》-習題9 列印,列印,列印