
zfill() method –
The zfill() method adds zeros ( 0 ) at the beginning of a string until it reaches the specified length.
Syntax –
string.zfill(len)
len – number which specify the desired length of the string
Example –
In [1]: string1 = 'python'
In [2]: string1.zfill(10)
Out[2]: '0000python'
In [3]: string1.zfill(20)
Out[3]: '00000000000000python'
In [4]: string1.zfill(0)
Out[4]: 'python'
Related Posts –
- Python String Method – Capitalize()
- Python String Method – title()
- Python String Method – center()
- Python String Method – count()
- Python String Method – startswith()
- Python String Method – endswith()
- Python String Method – find()
- Python String Method – index()
- Python String Method – isalnum()
- Python String Method – isalpha()
- Python String Method – isdecimal()
- Python String Method – isdigit()
- Python String Method – islower()
- Python String Method – istitle()
- Python String Method – isupper()
- Python String Method – join()
- Python String Method – lower()
- Python String Method – upper()
- Python String Method – swapcase()
- Python String Method – lstrip()
- Python String Method – rstrip()
- Python String Method – strip()
- Python String Method – replace()