格式化字符串-学习笔记
2016-07-03 20:37
162 查看
# 使用给定的宽度打印格式化后的价格列表
width = int(input('please enter width(>= 32):')) 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,'prince')) # item_with和prince_width引用header_format各自格式化了后面的字符串.在下面则是引用format. print('-' *width) print(format % (item_width,'Apple',price_width,0.4)) print(format % (item_width,'Pears',price_width,0.5)) print(format % (item_width,'Cantal oupes',price_width,1.92)) print(format % (item_width,'Dried Apricots(16 oz.)',price_width,8)) print(format % (item_width,'Prunes(4 lbs)',price_width,12))
相关文章推荐
- opensslmd5算法源码c++版
- Mysql各版本安装包下载地址
- 傅氏古碑考察记
- Java Web 学习笔记之一:服务器获取表单上传的文件
- js文件处理
- Android Studio Mac 常用快捷键
- TYVJ P1403 [NOIP2010]关押罪犯
- Spring-bean的装配
- Android使用ContentObserver进行实时短信填写
- Ubuntu QT for Android完整搭建过程
- dp专题
- WIN7系统32位或者64位运行ARCENGINE报错的解决方法
- 计算机信息数字化基础
- Java8 Lambda
- java static块详解
- 【MFC入门】之五 标准控件在可视化编程中的应用之对话框通用控件
- 如何根据图片找到图中的地点
- 【C#】Excel导出合并行和列并动态加载行与列
- POIExcel获取数据
- 注册审核