Python 3 教程 Python3 zfill()方法

norton · 2022-03-13 18:13:15 · 热度: 7

描述

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

语法

zfill()方法语法:

str.zfill(width)

参数

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

返回值

返回指定长度的字符串。

实例

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

#!/usr/bin/python3

str = "this is string example from codercto....wow!!!"
print ("str.zfill : ",str.zfill(40))
print ("str.zfill : ",str.zfill(50))

以上实例输出结果如下:

str.zfill :  this is string example from codercto....wow!!!
str.zfill :  000000this is string example from codercto....wow!!!

查看更多 Python 字符串内建函数

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册