Python3 zfill() Method
Description
The Python zfill() method returns a string of a specified length with the original string right-aligned and padded with leading zeros.
Syntax
Syntax of the zfill() method:
str.zfill(width)
Parameters
- width -- specifies the length of the string. The original string is right-aligned and padded with leading zeros.
Return Value
Returns a string of the specified length.
Example
The following example shows how to use the zfill() function:
#!/usr/bin/python3
str = "this is string example from runoob....wow!!!"
print ("str.zfill : ",str.zfill(40))
print ("str.zfill : ",str.zfill(50))
The output of the above example is:
str.zfill : this is string example from runoob....wow!!!
str.zfill : 000000this is string example from runoob....wow!!!
Python3 Strings