The zfill method
The zfill method returns a string filled with zeros to a given length. The desired string length is specified by the method parameter.
Syntax
string.zfill(string length)
Example
Let's apply the zfill method to our string:
txt = 'abc'
print(txt.zfill(6))
Result of code execution:
'000abc'
Example
Let's use the zfill method again, but in this case, we'll specify a number in the parameter that is less than the length of our string:
txt = 'abc'
print(txt.zfill(2))
As you can see from the result, we got back the original string:
'abc'