Python中zfill()方法的使用教程,pythonzfill
Python中zfill()方法的使用教程,pythonzfill
zfill()方法用零垫串来填充左边宽度。
语法
以下是zfill()方法的语法:
str.zfill(width)
参数
- width -- 这是字符串的最终宽度,即填充零后得到的宽度。
返回值
此方法返回补齐的字符串。
例子
下面的例子显示了zfill()方法的使用。
#!/usr/bin/python str = "this is string example....wow!!!"; print str.zfill(40); print str.zfill(50);
当我们运行上面的程序,它会产生以下结果:
00000000this is string example....wow!!! 000000000000000000this is string example....wow!!!
相关内容
- 在Python中处理字符串之isdecimal()方法的使用,pythonisde
- python对数组进行反转的方法,python数组反转
- Python中列表的一些基本操作知识汇总,python基本操作
- python操作mongodb根据_id查询数据的实现方法,mongodb_id
- 简单介绍Python2.x版本中的cmp()方法的使用,python2.xcmp
- 在Python中操作列表之List.append()方法的使用,pythonlist.
- Python中List.count()方法的使用教程,pythonlist.count
- python实现马耳可夫链算法实例分析,python实例分析
- 在Python中操作列表之list.extend()方法的使用,pythonlist.
- Python中List.index()方法的使用教程,pythonlist.index
评论关闭