Home >>Python String Methods >Python String zfill() Method

Python String zfill() Method

Python String zfill() Method

Python string zfill() method is used to add zeros (0) at the beginning of the given input string until it reaches the specified length. If the value of the length parameter is less than the length of the string then no filling of zeros is done.

Syntax:
string.zfill(len)

Parameter Values

Parameter Description
len This is a required parameter. It defines a number specifying the position of the element you want to remove.
Here is an example of Python zfill() method:

txt = "99"
x = txt.zfill(10)
print(x)

Output:
0000000099
Example 2:

a = "hello"
b = "welcome to PHPTPOINT"
c = "10.000"

print(a.zfill(10))
print(b.zfill(10))
print(c.zfill(10))

Output:
00000hello
welcome to PHPTPOINT
000010.000

No Sidebar ads