python 打印, 打印, 打印

2021-09-15 14:44 更新

練習(xí)9.打印, 打印, 打印

現(xiàn)在,你應(yīng)該明白這本書的模式是用做很多的練習(xí)來教會(huì)你新知識(shí)。我以你可能不明白的代碼開始教學(xué),然后在用更多的習(xí)題去解釋一些概念。即使你現(xiàn)在并不明白,經(jīng)過大量的練習(xí)之后你也能明白了。記錄你不明白的地方,然后堅(jiān)持做練習(xí)題,你會(huì)收獲更多。

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

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

print "Here are 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 much as we like.
Even 4 lines if we want, or 5, or 6.
"""

你看到的結(jié)果

$ python ex9.py
Here are the days:  Mon Tue Wed Thu Fri Sat Sun
Here are the months:  Jan
Feb
Mar
Apr
May
Jun
Jul
Aug

There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.

附加題

  1. 自己檢查結(jié)果,記錄你犯過的錯(cuò)誤,并且在下個(gè)練習(xí)中盡量不犯同樣的錯(cuò)誤。

常見問題

Q: 為什么當(dāng)我使用\n來換行的時(shí)候,%r就不生效了?

這就是%r格式的工作原理;你如何輸入的,它就如何打印輸出。

Q:為什么當(dāng)我在3個(gè)雙引號(hào)中間輸入空格的時(shí)候,會(huì)報(bào)錯(cuò)?

你應(yīng)該這樣寫"""而不是" " ",意思是說每兩個(gè)雙引號(hào)之間不能有空格。

Q:我的錯(cuò)誤經(jīng)常是一些拼寫錯(cuò)誤,這樣是不是很差?

在編程初期,大部分錯(cuò)誤都是一些簡單的錯(cuò)誤,比如拼寫問題,錯(cuò)別字,或者是將簡單的事情搞砸。這很正常,不用擔(dān)心,但是也要盡量不犯相同的錯(cuò)誤。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)