zfill() method returns a copy of the string with ‘0’ characters padded to the leftside of the given string.
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)) # Given length is less than # the length od original string print(text.zfill(10)) |
chevron_right
filter_none
Output :
0000000000geeks for geeks 00000geeks for geeks geeks for geeks
CODE 2
number = "6041"print(number.zfill(8)) number = "+6041"print(number.zfill(8)) text = "--anything%(&%(%)*^"print(text.zfill(20)) |
chevron_right
filter_none
Output :
00006041 +0006041 -0-anything%(&%(%)*^
Recommended Posts:
- numpy string operations | zfill() function
- Python | Pandas Series.str.zfill()
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- Python | Sorting string using order defined by another string
- Python | Merge Tuple String List values to String
- Python | Sort each String in String list
- Python | Convert List of String List to String List
- Python - Length of shortest string in string list
- Python - Remove front K characters from each string in String List
- Python - Remove String from String List
- Python | Delimited String List to String Matrix
- String Alignment in Python f-string
- String to Int and Int to String in Python
- Pad or fill a string by a variable in Python using f-string
- Python - Filter String Tuples if String lengths equals K
- How to split a string in C/C++, Python and Java?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

