通過閱讀「瞭解Python的難題」,我試圖修改練習6,以便了解發生了什麼。最初它包含:爲什麼輸出不同?
x = "There are %d types of people." % 10
binary = "binary"
do_not = "don't"
y = "Those who know %s and those who %s." % (binary, do_not)
print "I said: %r." % x
print "I also said: '%s'." % y
,併產生輸出:
print "I also said: %r." % y
:
I said: 'There are 10 types of people.'.
I also said: 'Those who know binary and those who don't.'.
爲了看到使用%s和%R在上線之間的區別,我取代了它
,現在獲得的輸出:
I said: 'There are 10 types of people.'.
I also said: "Those who know binary and those who don't.".
我的問題是:爲什麼現在有雙引號而不是單引號?
很好地解釋和展示 –
謝謝,清楚和直接的答案。現在我發現作者在書中提出了同樣的觀點。 – agtortorella