Definition
The center() method will center align the string, using a specified character (space is default) as the fill character.
Syntax
string.center(length, character)
Parameters
Parameter | Description |
---|---|
length | Required. The length of the returned string |
character | Optional. The character to fill the missing space on each side. Default is " " (space) |
Examples:
myString = "center of the world"
result = myString.center(20)
print(result)
# with padding "*"
withPadding = myString.center(20, '*')
print(withPadding)