Python 中的 zfill()(关键词:Python/zfill)

描述

Python zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0。

语法

zfill()方法语法:

str.zfill(width)

参数

width – 指定字符串的长度。原字符串右对齐,前面填充0。

返回值

返回指定长度的字符串。

实例

以下实例展示了 zfill()函数的使用方法:

>>> string = 'hello'
>>> string.zfill(10)
'00000hello'
>>> string.zfill(8)
'000hello'

参考文献:
1. http://www.runoob.com/python/att-string-zfill.html

猜你喜欢

转载自blog.csdn.net/qq_33528613/article/details/82526936