码迷,mamicode.com
首页 > 编程语言 > 详细

Python zfill()方法

时间:2017-10-18 16:43:29      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:字符   str   输出   pytho   class   ...   函数   bin   his   

描述

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

语法

zfill()方法语法:

str.zfill(width)

参数

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

返回值

返回指定长度的字符串。

实例

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

#!/usr/bin/python3

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

以上实例输出结果如下:

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

Python zfill()方法

标签:字符   str   输出   pytho   class   ...   函数   bin   his   

原文地址:http://www.cnblogs.com/wushuaishuai/p/7687398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!