这次的习题学习格式化控制符,在下面的代码中。
字符串中的格式化字符串类似规一个规定好只能盛放特定液体的罐子。牛奶瓶子装牛奶、茶杯装茶
%d:装10进制的整形数据
%s:装字符串类型的数据
%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 = True
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
输出结果为:
mystuff simengred$ python ex6.py
There are 10 types of people.
Those who know binary and those who don't.
I said : 'There are 10 types of people.'.
I also said 'Those