Saturday, March 10, 2018

String zfill() Method


String zfill() Method in Python 3


The zfill() method pads string on the left with zeros to fill width.

Syntax
str.zfill(width)

Parameters
width - This is final width of the string. This is the width which we would get after filling zeros.
Return Value
This method returns padded string.
Example
#!/usr/bin/python3
str = "this is string example....wow!!!"
print ("str.zfill : ",str.zfill(40))
print ("str.zfill : ",str.zfill(50))

Result
str.zfill : 00000000this is string example....wow!!!
str.zfill : 000000000000000000this is string example....wow!!!