Javatpoint Logo
Javatpoint Logo

Python String zfill() Method

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.



width : length of the string.


It returns a string.

Let's see some examples of zfill() method to understand it's functionality.

Python String zfill() Method Example 1

Let'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.


0000000Zfill Example

Python String zfill() Method Example 2

Here, we are passing width less than the string length therefore it returns the original string without filling zeros to the left.


Zfill Example

Python String zfill() Method Example 3

This 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.



Python Tuple Methods

Next TopicPython Strings

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA