Python學習之專用英語篇(2)

NakoMix發表於2018-08-08

原文連結:本辦法學Python
符號英文名稱
+ plus 加號
- minus 減號
/ slash 斜槓
* asterisk 星號
,comma 逗號
% percent 百分號
()parenthesis 圓括號
< less-than 小於號
<= less-than-equal 小於等於號

format string 格式化字串
%s
%d
%r 它的意思是不管什麼都列印出來

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 x
print y

print "I said: %r." % x
print "I also said: '%s'." % y

hilarious = False
joke_evaluation = "Isn't that joke so funny?! %r"

print joke_evaluation % hilarious

w = "This is the left side of..."
e = "a string with a right side."

print w + e

執行結果

>>> print(x)
There are 10 types of people.
>>> print(y)
Those who know binary and those who don't.
>>> print("I said:%r."%x)
I said:'There are 10 types of people.'.
>>> print("I also said:'%s'."%y)
I also said:'Those who know binary and those who don't.'.
>>> print("I also said:%r."%y)
I also said:"Those who know binary and those who don't.".

相關文章