Python center() method
Description
Python center() returns a new string with the original string centered and padded with spaces to the length width. The default fill character is a space.
Syntax
Syntax of the center() method:
str.center(width[, fillchar])
Parameters
- width -- the total width of the string.
- fillchar -- the fill character.
Return Value
This method returns a new string with the original string centered and padded with spaces to the length width.
Example
The following example demonstrates the center() method:
str
=
'
runoob
'
str
.
center
(
20
,
'
'
)
'
runoob
'
str
.
center
(
20
)
'
runoob
'
Python Strings