您的位置:首页 > 其它

学习笔记-20150519

2015-05-20 07:36 78 查看

字符串的合并和占位符的使用
注意在%号前不能有引号。



# -*- coding:utf-8 -*-
my_name ='中国'
my_age =35
my_height =74
my_weight =180
my_teeth ='White'
my_hair ='Brown'
print("Let's talk about %s."% my_name)
print("He's %d inch tall, %s"%(my_height, my_name))
#test注意
print("Let's add my height %d to my weight %d,and get the result: %d"%(my_height,my_weight,my_height+my_weight))


另一个例子:

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


运行结果:


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 who know binary and those who don't.'.
Isn't that Joke so funny?! False
This is the left side of ...a string with a right side.




来自为知笔记(Wiz)



附件列表

Image.png
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: