Tuesday, March 6, 2018

String center() Method


String center() Method in Python 3


The method center() returns centered in a string of length width. Padding is done using the specified fillchar. Default filler is a space.
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 a string that is at least width characters wide, created by padding the string with the character fillchar (default is a space).
Example

#!/usr/bin/python3

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