Python3 zfill() Method

Python3 字符串Python3 Strings


Description

The Python zfill() method returns a string of the specified length, with the original string right-aligned and filled with 0s in front.

Syntax

zfill() method syntax:

str.zfill(width)

Parameters

  • width -- The length of the specified string. The original string is right-aligned and filled with 0s in front.

Return Value

Returns a string of the specified length.

Example

The following example demonstrates the usage of the zfill() function:

#!/usr/bin/python3

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

The output result of the above example is as follows:

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

Python3 字符串Python3 Strings

Other Extensions