python 第三章 字符串-例1
1.字段宽度和精度
>>>'%.*s' % (10,'Gruido')
' Guido'
>>>'%.-*s' % (10,'Gruido')
'Guido '
详见例子
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,'Dried Apricots(16 oz.)',price_width,8)
print format %(item_width,'Prunes(4 1bs.)',price_width,12)
输出结果:
Please enter width:35
===================================
Item Price
-------------------------------------------------------
Apples 0.4
... ...
... ...
... ...
... ...
... ...
===================================
python 第三章 字符串-例1的更多相关文章
- Python第三章-字符串
第三章 字符串 3.1 基本字符串操作 Python的字符串和元组差不多,是不可以进行改变的,如果想改变值,可以尝试list序列化之后在进行修改. { website = 'http://ww ...
- 简学Python第三章__函数式编程、递归、内置函数
#cnblogs_post_body h2 { background: linear-gradient(to bottom, #18c0ff 0%,#0c7eff 100%); color: #fff ...
- Python第三章(北理国家精品课 嵩天等)
一.数字类型及其操作 整数:pow(x,y),想算多大,就算多大:以0b或0B开头表示二进制:以0o或0O开头表示八进制:以0x或0X开头表示十六进制. 浮点数:取值范围-10^308至10^308, ...
- <<C++ Primer>> 第三章 字符串, 向量和数组 术语表
术语表 第 3 章 字符串, 向量和数组 begin: 是 string 和 vector 的成员,返回指向第一个元素的迭代器.也是一个标准库函数,输入一个数字,返回指向该数字首元素的指针. 缓 ...
- python第三章:循环语句--小白博客
Python条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非 ...
- 2 python第三章文件操作
1.三元运算 三元运算又称三目运算,是对简单的条件语句的简写,如: 简单条件语句: if 条件成立: val = 1 else: val = 2 改成三元运算: val = 1 if 条件成立 els ...
- Python第三章-输入输出和运算符
输入输出和运算符 一.输入和输出 1.1 输出 `print()`函数用来向终端输出数据(其实也可以向文件输出数据,后面再讲) 可以传递多个参数,则输出的时候 python 会把多个参数的值用空格隔开 ...
- python第三章:函数
在前面章节中,介绍了一些input(),print(),len()等内建函数,还有random,math等标准库相关函数,这些都是可以直接使用的,但是很多时候,我们也是可以编写自己的函数. 看个例子: ...
- python基础三之字符串
Python的数据类型 数字(int),如1,2,3,用于计算. 字符串(str),如s = 'zxc',储存少量数据,进行操作. 布尔值(bool),True和False,用于进行判断. 列表(li ...
随机推荐
- GLSL 纹理贴图
#include <ork/render/FrameBuffer.h> #include <ork/scenegraph/SceneManager.h> #include &l ...
- 【转】Informix数据表结构分析资料整理之约束查询代码
原文地址:http://blog.csdn.net/xqf222/article/details/6271219 本文主要整理了Informix数据库相关系统表数据,已分析整个Informix数据表结 ...
- c++的函数模板和类模板
函数模板和普通函数区别结论: 函数模板不允许自动类型转化 普通函数能够进行自动类型转换 函数模板和普通函数在一起,调用规则: 1 函数模板可以像普通函数一样被重载 2 C++编译器优先考虑普通函数 3 ...
- LeetCode OJ 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- poj 3278 Catch That Cow bfs
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- 取URL得值
有这样一个URL:http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e,请写一段JS程序提取URL中的各个GET参数(参 ...
- hadoop---wordcount命令
[zznu@master file]$ hadoop jar ~/hadoop-2.5.2/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.2 ...
- Arch安装详解
选择安装方式 CD/USB Arch启动盘安装 使用Arch启动盘比较简单方便,没有额外设置,直接阅读下一步. USB flash installation media 启动盘制作: USB flas ...
- Xcode8中添加SnapKit框架报错,编译失败
既然SnapKit的作者说SnapKit已经支持Swift3.0了,那么我们就先来适配SnapKit,首先用Xcode8新建一个空项目,利用Cocoapods导入SnapKit. Podfile 打 ...
- mnesia
1.模式创建 mnesia:create_schema([node()|nodes()]).集群的节点之间创建模式 2.启动和停止 application:start(mnesia). applica ...