python数字、字符串对齐
来源:互联网 发布:淘宝聚划算有什么好处 编辑:程序博客网 时间:2024/05/17 07:04
#!/usr/bin/python
data1=5
data2=10str1 ='iot_history_%-2d'%data1 + ' ok'
str2 ='iot_history_%-2d'%data2 + ' ok'
print str1
print str2
输出:
iot_history_5 ok
iot_history_10 ok
'%*d'
%
(width,data)
上面的 * 对应 width,d 对应 data,输出的 data 占 width 个字符长度
或者直接
1
'%4d'
%
data
这样就是表明占4位,在%后面加一个 - 就是左对齐,位数可以通过len(max())获得
字符串对齐:
word="hello"
print word.center(20)
print word.center(20,"*") #居中输出,总共20个字符,word左右两侧各输出5个"*"号
print word.ljust(0)
print word.rjust(20)
print "%20s"%word #类似于word.rjust(30
0 0
- python数字、字符串对齐
- Python - 字符串对齐
- python coobook 2 ---字符串对齐
- 001_004 Python 字符串对齐
- python数字转成字符串
- python数字转成字符串
- python 数字转换字符串
- python数字转成字符串
- Python 字符串查找数字
- python数字转字符串
- python 数字、字符串、列表
- 轻松python文本专题-字符串对齐
- python字符串format中英文空格对齐问题
- python 数字转换成字符串
- Python字符串与数字转换
- python提取字符串中数字
- python 回文字符串 回文数字
- Python 字符串格式化 数字游戏
- jQuery中this与$(this)的区别
- sql 查询重复
- 检查字符串中是否包含某字符集合中的字符
- 存储过程
- centos 6.4编译gcc升级过程
- python数字、字符串对齐
- iptables 详解
- Material Design之FloatingActionButton的使用
- Java反射Demo
- 无限制免费版,完美您的WEB应用 PAZU WEB打印控件
- 5UCMS使用page标签调用栏目形象图
- 5.4.1 Polygon 函数和多边形填充模式
- jQuery学习笔记之二
- fopen参数中有b与没有b的区别