您的位置:首页 > 其它

【习题5】更多的变量和打印【第6天】

2016-03-09 14:26 316 查看
【代码】

#coding:utf-8
my_name='liujianqi'
my_age=25 # not a lie
my_height=172 # cm
my_weight=100 #kg
my_eyes='black'
my_teeth='white'
my_hair='black'

print "Let's talk about %s." % my_name
print "He's %d cm tall." %my_height
print "He's %d kg weight" %my_weight
print "Actually that's too heavy"
print "He's got %s eyes and %s hair." %(my_eyes,my_hair)
print "His teeth are usually %s depending on the coffee." %my_teeth

# this line is tricky,try to get it exactly right
print "If I add %d , %d,and %d I get %d"%(my_age,my_height,my_weight,my_age+my_height+my_weight)


【运行结果】:^_^

【补充:Python格式化字符】

%s 字符串 (采用str()的显示)

%r 字符串 (采用repr()的显示)

%c 单个字符

%b 二进制整数

%d 十进制整数

%i 十进制整数

%o 八进制整数

%x 十六进制整数

%e 指数 (基底写为e)

%E 指数 (基底写为E)

%f 浮点数

%F 浮点数,与上相同

%g 指数(e)或浮点数 (根据显示长度)

%G 指数(E)或浮点数 (根据显示长度)

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