Function Details: center

Description


Return a centered string of length width.


Extended Description


The center() method returns a new string padded with specified characters (spaces by default) to make it centered within a string of specified width. If the specified width is less than or equal to the length of the string, the original string is returned.


Read More about center from Python Documentation

Function Signature



Module: builtins

Class: str

Parameters



Parameter List


  • width: int
  • fillchar: str

Return


Returns a new string of specified width with the original string centered.


Return Type


str

Output

Explanation

This example demonstrates the basic usage of center(). It centers 'hello' in a string of width 10, padding with '-'.