Str zfill pads a string in python with zeros on left side and returns string with specified width.

Syntax of Str.zfill:

str.zfill(width)=>String

a='God is great'

a is string with length 12

a.zfill(15) Output: '000GOd is great'
str.zfill() in python
1.String zfill() in Python

It will return output of length 15 as specified width is 15 in zfill(15) method.As you can see in image above length of string is 12 and after applying zfill it had prefixed 3 zero’s in string a.

By SC

One thought on “Str.Zfill”

Comments are closed.