Latest web development tutorials

Python3 zfill () method

Python3 string Python3 string


description

Python zfill () method returns a string that specifies the length of the original string right justified, zero-padded front.

grammar

zfill () method syntax:

str.zfill(width)

parameter

  • width - Specifies the length of the string. The original string right justified, zero-padded front.

return value

Returns length of string.

Examples

The following example shows zfill () function to use:

#!/usr/bin/python3

str = "this is string example from w3big....wow!!!"
print ("str.zfill : ",str.zfill(40))
print ("str.zfill : ",str.zfill(50))

Examples of the above output results are as follows:

str.zfill :  this is string example from w3big....wow!!!
str.zfill :  000000this is string example from w3big....wow!!!

Python3 string Python3 string