Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python zfill() method

Python zfill() method

Python Strings Python Strings


Description

The Python zfill() method returns a string of a specified length with the original string right-aligned and padded with leading zeros.

Syntax

Syntax of the zfill() method:



str.zfill(width)

Parameters

Return Value

Returns a string of the specified length.

Example

The following example shows how to use 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:



00000000this is string example....wow!!!

000000000000000000this is string example....wow!!!


Python Strings Python Strings