Python String zfill() MethodLast Updated : 5 Jan 2026 Python zfill() method fills the string at left with 0 digit to make a string of length width. It returns a string contains a sign prefix + or - before the 0 digit. It returns original length string if the width is less than string length. Syntax of Python String zfill() MethodIt has the following syntax: Parameters
ReturnIt returns a string. Different Examples for Python String zfill() MethodLet's see some examples of zfill() method to understand it's functionality. Example 1Let's see an example which has width greater than string length. It returns a new string containing 0 to the left and total length is equal to width. Output: 0000000Zfill Example Example 2Here, we are passing width less than the string length therefore it returns the original string without filling zeros to the left. Output: Zfill Example Example 3This example describes the sign either + or - includes before the zero fills to the left of the string. See every value is filled after prefixing (+ or -) sign. Output: +000000100 -000000200 -0-Rohan-- Next TopicPython Strings |
We request you to subscribe our newsletter for upcoming updates.