The zfill() method pads string on the left with zeros to fill width.
Following is the syntax for zfill() method −
str.zfill(width)
width − This is final width of the string. This is the width which we would get after filling zeros.
This method returns padded string.
The following example shows the usage of zfill() method.
#!/usr/bin/python3 str = "this is string example....wow!!!" print ("str.zfill : ",str.zfill(40)) print ("str.zfill : ",str.zfill(50))
When we run above program, it produces the following result −
str.zfill : 00000000this is string example....wow!!! str.zfill : 000000000000000000this is string example....wow!!!