Python String center() Method


Contents

The The center() method in Python String returns centered in a string of length width. Thus, Padding is done making use of the specified fillchar. Space is the default filler.

Syntax

str.center(width[, fillchar])

Parameters

  • width − This is the total width of the string.
  • fillchar − This is the filler character.

Return Value

This method returns centered within a string of length width.

Example

The following example shows the use of center() method in Python String.

#!/usr/bin/python

str = "this is string example....wow!!!"
print "str.center(40, 'a') : ", str.center(40, 'a')

Result

str.center(40, 'a') :  aaaathis is string example....wow!!!aaaa

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial