Python zfill() Method
Description
The Python zfill() method returns a string of the specified length, with the original string right-aligned and padded with 0s on the left.
Syntax
zfill() method syntax:
str.zfill(width)
Parameters
- width -- Specifies the length of the string. The original string is right-aligned and padded with 0s on the left.
Return Value
Returns a string of the specified length.
Examples
The following example demonstrates the use of the zfill() function:
#!/usr/bin/python str = "this is string example....wow!!!"; print str.zfill(40); print str.zfill(50);
The output of the above example is as follows:
00000000this is string example....wow!!! 000000000000000000this is string example....wow!!!
Other Extensions
Python Strings