原文链接:本办法学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.".