Home >>Python String Methods >Python String center() Method
Python string center() method is used to align the string in center using a specified character whose default value is space as the fill character.
Syntax:string.center(length, character)
Parameter | Description |
---|---|
length | This is a required parameter. It defines the length of the returned string. |
character | This is an optional parameter. It defines the character to fill the missing space on each side. |
txt = "PHPTPOINT"
x = txt.center(20)
print(x)
txt = "PHPTPOINT"
x = txt.center(20, "*")
print(x)