You are doing zfill on list object. Instead, you need to perform zfill on each item of list. Below is the sample example for range 10:

>>> a = range(0, 10)

#                 v  this value represent the count of zeros
#                 v  It should be `7` in your case
>>> [str(i).zfill(10) for i in a]
['0000000000', '0000000001', '0000000002', '0000000003', '0000000004', '0000000005', '0000000006', '0000000007', '0000000008', '0000000009']

As per the str.zfill() document:

string.zfill(s, width)

Pad a numeric string s on the left with zero digits until the given width is reached. Strings starting with a sign are handled correctly.

Answer from Moinuddin Quadri on Stack Overflow
🌐
Tutorialspoint
tutorialspoint.com › python › string_zfill.htm
Python String zfill() Method
The Python String zfill() method does not fill the string if the length of the string is greater than the total width of the string after padding. Note: The zfill() method works similar to the rjust() method if we assign '0' to the fillchar ...
Discussions

Add a limit to `string.zfill` so it will raise an error to lengths bigger that the int in the brackets
Feature or enhancement Proposal: In the string.zfill() function, it won't process string-numbers (e.g.: "1234") with a length bigger than the input int. # Will do: # 1. a = 123 a_zfil... More on github.com
🌐 github.com
4
June 11, 2024
Series.str.zfill() behaves differently than str.zfill() from standard library
# Pandas >>> s = pd.Series(['-2', ... object # Python 3.6 >>> '-2'.zfill(5) '-0002' >>> '+5'.zfill(5) '+0005' People used to the standard library's str methods may expect Series.str.zfill() to behave differently, i.e. to treat '+' and '-' as special characters and move them to the left of the resulting strings if necessary. This could be a feature, not a bug, but ... More on github.com
🌐 github.com
4
April 29, 2018
Why won't zfill work on string objects in python? - Stack Overflow
I am trying to convert dates passed into this function YYYY-M?M-D?D into a tuple of an integer and a list, with separate elements for each section of the date. Because of how I am receiving data an... More on stackoverflow.com
🌐 stackoverflow.com
July 9, 2019
How would you add zeros to the beginning of an Integer, such that there are 4 total digits in the number?
zfill or format are not obscure at all. A python integer cannot have leading zeros. It's simply not possible. zfill and format work with strings. You can also use f-strings to add zeros to a string: data = 15 print(f"{data:0>4}") That said this sounds like an XY problem. We could help a lot more if you told us what problem you are trying to solve, not just how you are trying to solve it. What's the big picture here? http://xyproblem.info More on reddit.com
🌐 r/learnpython
4
2
February 16, 2022
People also ask

Should I use zfill or an f-string?
Use zfill for an existing string and sign-aware text padding; use an f-string when the source is numeric and the complete output format is known.
🌐
pythonpool.com
pythonpool.com › home › tutorials › python zfill(): zero-pad strings, numbers, and signs
Python zfill(): Zero-Pad Strings, Numbers, and Signs
How do I add leading zeros in Python?
Convert the value to a string and call value.zfill(width), or use a numeric format such as f'{number:05d}' when formatting a number.
🌐
pythonpool.com
pythonpool.com › home › tutorials › python zfill(): zero-pad strings, numbers, and signs
Python zfill(): Zero-Pad Strings, Numbers, and Signs
🌐
Programiz
programiz.com › python-programming › methods › string › zfill
Python String zfill()
Suppose, the initial length of the string is 10. And, the width is specified 8. In this case, zfill() doesn't fill '0' digits to the left and returns a copy of the original string.
🌐
Narkive
zope.zope.narkive.com › fGP21UIS › problem-with-zfill
problem with zfill
Post by Jamie Heilman The zfill method wasn't added to str types until python 2.2.2b1. http://python.org/2.2.2/NEWS.txt Thanks... that seems to be a solution to my problem.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › zfill.html
zfill — Python Reference (The Right Way) 0.1 documentation
Returns the numeric string left filled with zeros in a string of specified length · A sign prefix is handled correctly. The original string is returned if width is less than or equal to len(str)
🌐
W3Schools
w3schools.com › python › ref_string_zfill.asp
Python String zfill() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The zfill() method adds zeros (0) at the beginning of the string, until it reaches the specified length.
Find elsewhere
🌐
Python Pool
pythonpool.com › home › tutorials › python zfill(): zero-pad strings, numbers, and signs
Python zfill(): Zero-Pad Strings, Numbers, and Signs
July 13, 2026 - If input may contain non-digit characters, validate it before padding. zfill() will pad any string, including "A7" or "7A", so the method should not be treated as numeric validation.
🌐
Codingem
codingem.com › home › python string zfill() method: a complete guide (with examples)
Python String zfill() Method: A Complete Guide (with Examples)
November 1, 2022 - For instance, let’s add zeros ... now 15 in length due to the zero-filling. If the length of the string is greater than what is passed into the zfill(), the method does nothing....
🌐
datagy
datagy.io › home › python posts › python strings › python zfill & rjust: pad a string in python
Python zfill & rjust: Pad a String in Python • datagy
December 16, 2022 - # Zero Padding in Python with Sign Prefixes a_number = '+13' print(a_number.zfill(5)) # Returns: +0013 · We can see that Python intelligently moved the sign prefix to the front of the string! This allows us to easily ensure that sign prefixes are respected. One important thing to note here is that the sign prefix is included in the width of the string.
🌐
Toppr
toppr.com › guides › python-guide › references › methods-and-functions › methods › string › zfill › python-string-zfill
Python zfill() function | Why do we use Python String zfill() function? |
September 27, 2021 - The syntax followed by Python zfill() is as below: ... width – integer value specifying the length of the output string with 0 digits filled to the left of the string until it reaches the specified width. Note – If the width parameter is not specified, the Python interpreter throws a TypeError exception.
🌐
GeeksforGeeks
geeksforgeeks.org › python-string-zfill
Python String zfill() - GeeksforGeeks
January 2, 2025 - Let’s see how zfill() handles a string longer than the specified width: ... The string "Python" has a length of 6, which is greater than the specified width of 4.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 20868
Series.str.zfill() behaves differently than str.zfill() from standard library · Issue #20868 · pandas-dev/pandas
April 29, 2018 - # Pandas >>> s = pd.Series(['-2', ... object # Python 3.6 >>> '-2'.zfill(5) '-0002' >>> '+5'.zfill(5) '+0005' People used to the standard library's str methods may expect Series.str.zfill() to behave differently, i.e. to treat '+' and '-' as special characters and move them to the left of the resulting strings if necessary. This could be a feature, not a bug, but ...
Author: pandas-dev
🌐
Stack Overflow
stackoverflow.com › questions › 56956264 › why-wont-zfill-work-on-string-objects-in-python
Why won't zfill work on string objects in python? - Stack Overflow
July 9, 2019 - For whatever reason, zfill just won't work. I have checked to see if the date sections were strings, and they were. I am completely lost. ... split_date.replace(date_section, date_section.zfill(2)) looks suspicious to me. Remember that str.replace does nothing unless you assign the result to something. ... As an aside, you should not be raising syntax errors here. ... Because it's not a syntax error, which implies an error in the python source code, which is encountered at compile time by the parser.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 3.0.5 documentation - PyData |
Differs from str.zfill() which has special handling for ‘+’/’-’ in the string. ... Note that 10 and NaN are not strings, therefore they are converted to NaN. The minus sign in '-1' is treated as a special character and the zero is added to the right of it (str.zfill() would have moved it to the left).
🌐
Codecademy
codecademy.com › docs › python › strings › .zfill()
Python | Strings | .zfill() | Codecademy
November 19, 2023 - Note: The .zfill() method does not change the string it is used on. ... Learn to analyze and visualize data using Python and statistics.
🌐
AskPython
askpython.com › python › string › python-string-zfill
Python string zfill() - AskPython
August 6, 2022 - The Python string zfill() function belongs to the String class, and can only be used on string objects.
🌐
CMSDK
cmsdk.com › python › python-zfill-not-working.html
Python
December 21, 2016 - How to Create the Perfect Website for Online Courses · What is Dict and List comprehensions are