ex5.py
2016-08-07 16:59
239 查看
ex5.py
name = 'Zed A. Shaw'
age = 35 # not a lie
height = 74 * 2.54 # inches convert to centimeters
weight = 180 * 0.4535924 # 1bs convert to kilograms
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'
print "Let's talk about %s." % name
print "He's %d centimeters tall." % height
print "He's %d kilograms heavy." % weight
print "Actually that's not too heavy."
print "He's got %s eyes and %s hair." %(eyes, hair)
print "His teeth are usually %s depending on the coffee." % teeth
# this line is tricky, try to get it exactly right
print "If I add %d, %d, and %d I get %d." %(age, height, weight, age + height + weight)
将变量的内容传递到字符串当中(这样说也许欠妥当),通过%连接字符串和变量名,在字符串当中用%r,%s等格式符来获得字符串之外的变量内容,
%s 字符串 (采用str()的显示)
%r 字符串 (采用repr()的显示)
%c 单个字符
%b 二进制整数
%d 十进制整数
%i 十进制整数
%o 八进制整数
%x 十六进制整数
%e 指数 (基底写为e)
%E 指数 (基底写为E)
%f 浮点数
%F 浮点数,与上相同
%g 指数(e)或浮点数 (根据显示长度)
%G 指数(E)或浮点数 (根据显示长度)
%% 字符"%"
name = 'Zed A. Shaw'
age = 35 # not a lie
height = 74 * 2.54 # inches convert to centimeters
weight = 180 * 0.4535924 # 1bs convert to kilograms
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'
print "Let's talk about %s." % name
print "He's %d centimeters tall." % height
print "He's %d kilograms heavy." % weight
print "Actually that's not too heavy."
print "He's got %s eyes and %s hair." %(eyes, hair)
print "His teeth are usually %s depending on the coffee." % teeth
# this line is tricky, try to get it exactly right
print "If I add %d, %d, and %d I get %d." %(age, height, weight, age + height + weight)
将变量的内容传递到字符串当中(这样说也许欠妥当),通过%连接字符串和变量名,在字符串当中用%r,%s等格式符来获得字符串之外的变量内容,
格式符为真实值预留位置,并控制显示的格式。格式符可以包含有一个类型码,用以控制显示的类型,如下:
%s 字符串 (采用str()的显示)
%r 字符串 (采用repr()的显示)
%c 单个字符
%b 二进制整数
%d 十进制整数
%i 十进制整数
%o 八进制整数
%x 十六进制整数
%e 指数 (基底写为e)
%E 指数 (基底写为E)
%f 浮点数
%F 浮点数,与上相同
%g 指数(e)或浮点数 (根据显示长度)
%G 指数(E)或浮点数 (根据显示长度)
%% 字符"%"
相关文章推荐
- android面试(基础篇 8)
- 一. 开始 Xcode 7 编程之旅
- Android开发人员不得不收集的代码
- ex4.py
- java synchronized
- springmvc学习(三)
- 动态规划-满减优惠
- 13 ftp软件安装过程
- The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 经验分享之在 CentOS 7 上搭建支持 HTTP 协议的 SVN 服务器
- 知道SG函数是干什么的
- Spring的事务管理器
- 浅析数据结构与算法12--无向图相关算法基础
- JSP实现数据传递与保存
- ex3.py
- (十六)Spring框架——AOP
- uva146 ID codes
- 161.In your database instance, the user sessions are connected to the database server from the remot
- 最新在Linux服务器上安装VNC并进行远程桌面连接 推荐
- HDU5792(2016多校第五场)——World is Exploding(树状数组,离散化)