#coding: utf-8
name = 'Jerry'
age = 22 # not a lie
height = 74 # inches
weight = 180 # lbs
eyes = 'Black'
teeth = 'White'
hair = 'Black'
print "Let's talk about %s." % name
print "He's %d inches tall." % height
print "He's %d pounds heavy." % weight
print "Actually that's 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)
# %c 格式化字符及其ASCII码
# %s 格式化字符串
# %d 格式化整数
# %u 格式化无符号整型
# %o 格式化无符号八进制数
# %x 格式化无符号十六进制数
# %X 格式化无符号十六进制数(大写)
# %f 格式化浮点数字,可指定小数点后的精度
# %e 用科学计数法格式化浮点数
# %E 作用同%e,用科学计数法格式化浮点数
# %g %f和%e的简写
# %G %f 和 %E 的简写
# %p 用十六进制数格式化变量的地址
# %r 不管什么都打印出来
print round(1.7333) # 将浮点型四舍五入
ex5.py 更多的变量和打印
最新推荐文章于 2021-12-08 13:23:15 发布