Python String | zfill ()



Syntax :

 str.zfill (length) 

Parameters :

length: length is the length of the returned string from zfill () with `0` digits filled to the leftside.

Return:

 Returns a copy of the string with `0` characters padded to the leftside of the given string. 

CODE 1

text = "geeks for geeks"

 

print (text.zfill ( 25 ))

 

print (text.zfill ( 20 ))

 
# Specified length less
# original line length

print (text.zfill ( 10 ))

Output:

 0000 000000geeks for geeks 00000geeks for geeks geeks for geeks 

Code 2

number = "6041"

print (number.zfill ( 8 ))

 

number = "+ 6041"

print (number.zfill ( 8 ))

 

text = "- anything% (& amp;% (%) * ^"

print (text.zfill ( 20 ))

Output:

 00006041 +0006041 -0-anything% (& amp;% (%) * ^