Description Of Python Center() Method

The center(n , 'char') character string method in Python returns a centered string in a string of length n by completing the right and left of the string with the 'char' character chosen as a parameter. The padding 'char' character is optional and in the ignored case the default padding is the space character.

Center() Method Parameters & Syntax

Syntax[, fillchar])


  1. width: This is the total width of the string.
  2. fillchar: This is the fill character.

Example (filling using the '*' character)

s="Python Programming"
s =, '*')
# output: '******Python Programming******'

Example (filling using space character)

s =
# output: ' Python '

Younes Derfoufi
2 thoughts on “The Python center() method”

Leave a Reply