在Python中处理字符串之ljust()方法的使用简介,pythonljust
在Python中处理字符串之ljust()方法的使用简介,pythonljust
ljust()方法返回字符串左对齐的字符串长度宽度。填充是通过使用指定的fillchar(默认为空格)。如果宽度小于len(s)返回原始字符串。
语法
以下是ljust()方法的语法:
str.ljust(width[, fillchar])
参数
- width -- 这是填充后字符串的总长度。
- fillchar -- 这是填充符,默认为空格。
返回值
此方法返回字符串左对齐的字符串的长度宽度。填充是通过使用指定fillchar(默认为空格)。如果宽度小于len(s),返回原始字符串。
例子
下面的例子显示了ljust()方法的使用。
#!/usr/bin/python str = "this is string example....wow!!!"; print str.ljust(50, '0');
当我们运行上面的程序,它会产生以下结果:
this is string example....wow!!!000000000000000000
相关内容
- Python中用于转换字母为小写的lower()方法使用简介,py
- Python中的lstrip()方法使用简介,pythonlstrip
- Python2.x版本中maketrans()方法的使用介绍,python2.xmaketra
- 在Python中操作字符串之replace()方法的使用,pythonreplac
- Python中的rfind()方法使用详解,pythonrfind
- Python3.2中Print函数用法实例详解,python3.2print
- 用Python操作字符串之rindex()方法的使用,pythonrindex
- Python中random模块用法实例分析,pythonrandom
- Python递归遍历列表及输出的实现方法,python递归遍输出
- python抓取百度首页的方法,python抓取首页
评论关闭