Articles → PYTHON → Center Function In Python

Center Function In Python






Purpose




  1. If the value of the width parameter is less than or equal to the number of characters in the string, then no filler will be added on either side of the string
  2. If the value of the width parameter is one more than the number of characters in the string, then filler will be added on the left-hand side of the string
  3. If the value of the width parameter is greater than the number of characters in the string, then filler will be added on both sides of the string

Example


str = "this is string example"
print ("width is less than number of string characters -->", str.center(18, '*'))
print ("width is equal to number of string characters -->", str.center(22, '*'))
print ("width is one more than number of string characters -->", str.center(23, '*'))
print ("width is more than number of string characters -->", str.center(24, '*'))



Output


Picture showing the output of center function in python



Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, February 20, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250