zfill()
« All String methods
zfill(): Fill the string with zeros
Fill zeros up to the input length of the string
my_str='plus2net'
output=my_str.zfill(15)
print(output)
my_str='25'
output=my_str.zfill(5)
print(output)
output is here
0000000plus2net
00025
Using Integer
If we are using any integer then we have to convert the same to string by using str() before using. Here is the error message
AttributeError: 'int' object has no attribute 'zfill'
id=str(45) #convert to string
print(id.zfill(5)) # 00045
« All String methods
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com