center

Description

Returns the string centered in a string of specified length.

Syntax

str. center(width[, fillchar])

width
Required. The width of the field containing the string.
fillchar
Optional. Specifies the padding character (default is a space).

Return Value

str

Time Complexity

#TODO

Remarks

The original string is returned if width is less than or equal to len(str).

Example

>>> "ABC".center(10)
'   ABC    '
>>> "ABC".center(10, "#")
'###ABC####'
>>> "ABC".center(2, "#")
'ABC'