【Python】Learn Python the hard way, ex5 格式化字符串
2015-10-06 22:45
701 查看
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实现
- 克隆选择算法-python实现
- 细菌觅食算法-python实现
- 蝙蝠算法-python实现
- 人工免疫算法-python实现
- 人工鱼群算法-python实现
- 人工蜂群算法-python实现
- 粒子群优化算法-python实现
- 差分进化算法-python实现
- 简单遗传算法-python实现
- 【Python】Learn Python the hard way, ex4 使用变量
- python requests的安装与简单运用
- 【Python】Learn Python the hard way, ex3 运算符,浮点数
- Python正则表达式学习小结
- 【Python】Learn Python the hard way, ex2 注释
- 【Python】Learn Python the hard way, ex1 简单print语句
- Python连接MySQL ---mysql-connector-python-2.1.3-py3.4-winx64.msi
- 【Python】Learn Python the hard way, ex0 学习使用Terminal
- python收集
- Python 面向对象