Javatpoint Logo
Javatpoint Logo

Python String Center() Method

Python center() method alligns string to the center by filling paddings left and right of the string. This method takes two parameters, first is a width and second is a fillchar which is optional. The fillchar is a character which is used to fill left and right padding of the string.

Signature

Parameters

  • width (required)
  • fillchar (optional)

Return Type

It returns modified string.

Python String Center() Method Example 1:default fill char

Here, we did not pass second parameter. By default it takes spaces.

Output:

Old value: Hello Javatpoint
New value:   Hello Javatpoint

Python String Center() Method Example 2

Here, we are providing padding char (optional) parameter as #. See the example.

Output:

Old value: Hello Javatpoint
New value: ##Hello Javatpoint##

Python String Center() Method Example 3

Output:

Old value: Hello Javatpoint
New value: !!Hello Javatpoint!!

Next TopicPython Strings




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA