Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python center() method

Python center() method

Python Strings Python Strings


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

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 Python Strings