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 ...
随机推荐
- mac 修改系统配置参数 主机名 等
mac 修改系统配置参数,可以使用 命令 scutil 参考网址: https://developer.apple.com/library/mac/documentation/Darwin/Refer ...
- C#递归复制文件夹
/// <param name="sources">原路徑</param> /// <param name="dest">目 ...
- C 语言资源大全中文版
C 语言资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-c 是 koz.ross 发起维护的 C 语言资源列表,内容包括了: ...
- android在其他线程中访问UI线程的方法
1.Activity.runOnUiThread( Runnable ) 2.View.post( Runnable ) 3.View.postDelayed( Runnable, long ) 4. ...
- 5大AR应用窥探移动未来~你见过吗?
摘要:随着可穿戴设备的不断升温,尤其是Google Glass的出现,让AR技术再次走进我们的视线.以下尾随DevStore小编看看这5款优秀的AR应用,有木有闪到你的眼~ 眼下移动开发人员可选的AR ...
- Spring2.5学习3.3_@Autowire注解实现手动装配
@Autowired默认按类型装配,假设我在personDao 字段上加了@Autowired注解,那么就会默认取personDao 字段的类型在Spring容器中寻找与这个类型匹配的bean,寻找到 ...
- HP-UX查看版本
首先采用uname -a查看服务器类型 $ uname -a HP-UX WEBDB1 B.11.31 U ia64 0749665296 unlimited-user license 服务器的 ...
- 实现 select中指定option选中触发事件
我们在用到下拉列表框select时,需要对选中的<option>选项触发事件,其实<option>本身没有触发事件方法,我们只有在select里的onchange方法里触发. ...
- RR模式下的事务隔离
<pre name="code" class="html">mysql> select * from t100; Session 2: +-- ...
- 实例:怎样使用 Netty 下载文件
本实例主要參考的是官网的examples:点击这里 使用场景:client向Netty请求一个文件,Netty服务端下载指定位置文件到client. 本实例使用的是Http协议,当然,能够通过简单的改 ...