这篇教程Python zfill()方法写得很实用,希望能帮到您。 描述Python zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0。 语法zfill()方法语法: str.zfill(width) 参数- width -- 指定字符串的长度。原字符串右对齐,前面填充0。
返回值返回指定长度的字符串。 实例以下实例展示了 zfill()函数的使用方法: #!/usr/bin/pythonstr = "this is string example....wow!!!";print str.zfill(40);print str.zfill(50); 以上实例输出结果如下: 00000000this is string example....wow!!!000000000000000000this is string example....wow!!! Python upper()方法 Python List cmp()方法 |