python中字符串的ljust、rjust、center方法讲解
2013-07-05 12:39
411 查看
python中字符串的ljust、rjust、center方法讲解
这三种方法的用法差不多:S.ljust(width[, fillchar]),即长度加占位符,默认为空格,这三种在格式化输出时用着非常方便。
如:
>>> a="Hello world"
>>> print a.rjust(20)
' Hello world'
>>> print a.ljust(20)
'Hello world '
>>> print a.center(20)
' Hello world '
>>> print a.rjust(20,'*')
'*********Hello world'
>>> print a.ljust(20,'*')
'Hello world*********'
>>> print a.center(20,'*')
'****Hello world*****'
注:如果width小于字符串的长度,则完整输出字符串
本文出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/1242076
这三种方法的用法差不多:S.ljust(width[, fillchar]),即长度加占位符,默认为空格,这三种在格式化输出时用着非常方便。
如:
>>> a="Hello world"
>>> print a.rjust(20)
' Hello world'
>>> print a.ljust(20)
'Hello world '
>>> print a.center(20)
' Hello world '
>>> print a.rjust(20,'*')
'*********Hello world'
>>> print a.ljust(20,'*')
'Hello world*********'
>>> print a.center(20,'*')
'****Hello world*****'
注:如果width小于字符串的长度,则完整输出字符串
本文出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/1242076
相关文章推荐
- python中字符串的ljust、rjust、center方法讲解
- python中字符串的ljust、rjust、center方法讲解
- python中字符串的ljust、rjust、center方法讲解
- python 字符串创建,遍历,切片,格式化ljust rjust center,find,replace,split,repr,str
- python str方法之ljust、rjust、center
- python中字符串的ljust、rjust、center
- Pandas 文本数据方法 pad( ) center( ) ljust() rjust() zfill()
- 在Python中处理字符串之ljust()方法的使用简介
- 在Python中处理字符串之ljust()方法的使用简介
- python ljust,rjust,center,zfill对齐使用方法
- [python]字符串的ljust方法
- python: center、ljust、rjust 函数
- python3----ljust rjust center
- Pandas 文本数据方法 pad( ) center( ) ljust() rjust() zfill()
- python 通过字符串调用对象属性或方法的实例讲解
- 简介Python中用于处理字符串的center()方法
- Python 有关字符串方法完全讲解--视频随堂笔记
- Python: ljust()|rjust()|center()字符串对齐
- 简介Python中用于处理字符串的center()方法
- python字符串内建函数方法讲解