my_name = 'Gao'
my_age = 31 # not a lie
my_height = 174 # cm
my_weight = 80 # 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 heavy." % my_weight
print "Actually that's not 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)
'''
Test Result:
Let's talk about Gao.
He's 174 cm tall.
He's 80 kg heavy.
Actually that's not too heavy.
He's got Black eyes and Black hair.
His teeth are usually White depending on the coffee.
If I add 31, 174, and 80 I get 285.
'''
心得:
格式化字符串之前用得不多,今后可以多使用
本文详细介绍了个人属性的描述方式,包括身高、体重、眼睛颜色、头发颜色、牙齿颜色等,并通过代码展示了如何进行简单的数学计算。同时,分享了如何在Python中使用字符串格式化方法来展示这些属性。
475

被折叠的 条评论
为什么被折叠?



