首页 > 其他 > 详细

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

时间:2016-03-09 15:32:25      阅读:285      评论:0      收藏:0      [点我收藏+]

【代码】

 1 #coding:utf-8   
 2 my_name=liujianqi
 3 my_age=25 # not a lie
 4 my_height=172 # cm
 5 my_weight=100 #kg
 6 my_eyes=black
 7 my_teeth=white
 8 my_hair=black 
 9 
10 print "Let‘s talk about %s." % my_name
11 print "He‘s %d cm tall." %my_height
12 print "He‘s %d kg weight" %my_weight
13 print "Actually that‘s too heavy"
14 print "He‘s got %s eyes and %s hair." %(my_eyes,my_hair)
15 print "His teeth are usually %s depending on the coffee." %my_teeth
16 
17 # this line is tricky,try to get it exactly right
18 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)或浮点数 (根据显示长度)

 

%%    字符"%"

 

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

原文:http://www.cnblogs.com/liujianqi/p/5258047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!