python ljust,rjust,center,zfill对齐使用方法
2016-12-05 11:30
387 查看
字符串在输出时的对齐:
S.ljust(width,[fillchar])
#输出width个字符,S左对齐,不足部分用fillchar填充,默认的为空格。
S.rjust(width,[fillchar]) #右对齐
S.center(width, [fillchar]) #中间对齐
S.zfill(width) #把S变成width长,并在右对齐,不足部分用0补足
实例
S.ljust(width,[fillchar])
#输出width个字符,S左对齐,不足部分用fillchar填充,默认的为空格。
S.rjust(width,[fillchar]) #右对齐
S.center(width, [fillchar]) #中间对齐
S.zfill(width) #把S变成width长,并在右对齐,不足部分用0补足
实例
1 >>> str = "this is string example....wow!!!"; 2 >>> str.ljust(50,'0') 3 'this is string example....wow!!!000000000000000000' 4 >>> str.ljust(50) 5 'this is string example....wow!!! ' 6 >>> str.rjust(50) 7 ' this is string example....wow!!!' 8 >>> str.rjust(50,'0') 9 '000000000000000000this is string example....wow!!!' 10 >>> str.center(50,'0') 11 '000000000this is string example....wow!!!000000000' 12 >>> str.center(50) 13 ' this is string example....wow!!! ' 14 >>> str.zfill(50) 15 '000000000000000000this is string example....wow!!!' 16 >>>
相关文章推荐
- 在Python中处理字符串之ljust()方法的使用简介
- python center, ljust, rjust
- Python中的rjust()方法使用详解
- Python中zfill()方法的使用教程
- Python: ljust()|rjust()|center()字符串对齐
- python中字符串的ljust、rjust、center方法讲解
- Python中的rjust()方法使用详解
- python str方法之ljust、rjust、center
- Pandas 文本数据方法 pad( ) center( ) ljust() rjust() zfill()
- python中字符串的ljust、rjust、center方法讲解
- Pandas 文本数据方法 pad( ) center( ) ljust() rjust() zfill()
- python中字符串的ljust、rjust、center方法讲解
- Python中zfill()方法的使用教程
- 在Python中处理字符串之ljust()方法的使用简介
- python中字符串的ljust、rjust、center方法讲解
- Python2.5使用新浪微博Python SDK遇到的问题与解决方法
- Python strip lstrip rstrip使用方法(字符串处理空格)
- 使用MSVC进行SSE2优化时内存对齐的方法
- Python中使用中文的方法
- 【原】Python/C API使用方法简介 (在C/C++中嵌入Python)