Beginning Python From Novice to Professional (4) - 演示样本格式字符串
$ gedit price.py
#!/usr/bin/env python
width = input('Please enter width: ')
price_width = 10
item_width = width - price_width
header_format = '%-*s%*s'
format = '%-*s%*.2f'
print '=' * width
print header_format % (item_width, 'Item', price_width, 'Price')
print '-' * width
print format % (item_width, 'Apples',price_width,0.4)
print format % (item_width, 'Pears',price_width,0.5)
print format % (item_width, 'Cantaloupes',price_width,1.92)
print format % (item_width, 'Apricots',price_width,8)
print format % (item_width, 'Prunes',price_width,12)
print '=' * width
$ python price.py
Please enter width: 35
===================================
Item Price
-----------------------------------
Apples 0.40
Pears 0.50
Cantaloupes 1.92
Apricots 8.00
Prunes 12.00
===================================
减号(-)用来左对齐数值
星号(*)分辨率从表达元组读取参数
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Beginning Python From Novice to Professional (4) - 演示样本格式字符串的更多相关文章
- Beginning Python From Novice to Professional (7) - 类别
类别 创建一个简单的类: #!/usr/bin/env python __metaclass__ = type class Person: def setName(self,name): self.n ...
- Beginning Python From Novice to Professional (9) - Socket
Socket 小型server: #!/usr/bin/env python import socket s = socket.socket() host = socket.gethostname() ...
- Beginning Python From Novice to Professional (5) - 条件与循环
条件与循环 条件运行: name = raw_input('What is your name? ') if name.endswith('Gumby'): print 'Hello, Mr.Gumb ...
- Beginning Python Chapter 1 Notes
James Payne(American)编写的<Beginning Python>中文译作<Python入门经典>,堪称是Python的经典著作. 当然安装Python是很简 ...
- Python从菜鸟到高手(7):字符串
1. 单引号字符串和转义符 字符串与数字一样,都是值,可以直接使用,在Python控制台中直接输入字符串,如"Hello World",会按原样输出该字符串,只不过用单引号括了 ...
- 模式识别 - 处理多个演示样本研究(MIL)特点(matlab)
处理多个演示样本研究(MIL)特点(matlab) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/27206325 多演示样例学习 ...
- Cocos2d-x 3.2 Lua演示样本CocosDenshionTest(音频测试)
Cocos2d-x 3.2 Lua演示样本CocosDenshionTest(音频测试) 本篇博客介绍Cocos2d-x 3.2中Lua演示样例的音频測试.Cocos2d-x使用SimpleAudi ...
- java注意事项演示 地图产生表 演示样本 来自thinking in java 4 20代码的章
java注意事项演示 地图产生表 演示样本 来自thinking in java 4 20代码的章 thinking in java 4免费下载:http://download.csdn.net/d ...
- Python第三天 序列 5种数据类型 数值 字符串 列表 元组 字典 各种数据类型的的xx重写xx表达式
Python第三天 序列 5种数据类型 数值 字符串 列表 元组 字典 各种数据类型的的xx重写xx表达式 目录 Pycharm使用技巧(转载) Python第一天 安装 shell ...
随机推荐
- Google Ads Encryption Key
aes | floyd's Google Ads Encryption Key
- Swift - 点击输入框外部屏幕关闭虚拟键盘
我们如果把文本框的Return Key设置成Done,然后在storyboard中将文本框的Did End On Exit事件在代码里进行关联.同时关联代码里调用文本框的resignFirstResp ...
- PowerShell 在线教程 4
PowerShell 在线教程 4 认识Powershell 介绍和安装 自定义控制台 快速编辑模式和标准模式 快捷键 管道和重定向 Powershell交互式 数学运算 执行外部命令 命令集 别 ...
- air ios 输入遮挡问题
<!-- Adobe AIR Application Descriptor File Template. Specifies parameters for identifying, instal ...
- 友情转发一则Erlang招聘广告
新锐手游开发公司WalkYY,招聘Erlang游戏服务端开发工程师若干名,要求有半年以上Erlang游戏服务端开发经验,熟悉Erlang OTP和MySQL数据库.公司团队靠谱,发展空间大,有意者请发 ...
- Maven-1:下载&安装
(一)下载 下载网址:http://maven.apache.org/download.cgi 版本:3.0.5 (二)安装 1.解压至目录:F:\Kevin\software\apache-mave ...
- ThinkPhp学习03
原文:ThinkPhp学习03 一.ThinkPHP 3 的输出 (重点) a.通过 echo 等PHP原生的输出方式在页面中输出 b.通过display方法输出 想分配变量可以使用as ...
- InputStream中read()与read(byte[] b)(转)
read()与read(byte[] b)这两个方法在抽象类InputStream中前者是作为抽象方法存在的,后者不是,JDK API中是这样描述两者的: 1:read() : 从输入流中读取数据的下 ...
- html浏览器兼容性的 JavaScript语法
1. 在FireFox中能够使用与HTML节点对象ID属性值同样的JS变量名称.可是IE中不行. 解决的方法:在命名上区分HTML节点对象ID属性值和JS变量 2. IE不支持JS ...
- Xcode免证书真机调试,解决cannot read entitlement data问题
本文是根据某个帖子写的(帖子链接在最后放出),但是在配置的过程中,遇到了一个纠结的问题,这个问题折腾了我N久,一直没搞明白到底是什么原因,问题如下: 按照原帖上写的每一步去做了,但是在最后编译的时候出 ...