Python3 center () method
center () method returns the width of the width of a specified string centered, fillchar to fill characters, the default is spaces.
grammar
center () method syntax:
str.center(width[, fillchar])
parameter
- width - the total width of the string.
- fillchar - filled characters.
return value
Returns the width of the width of a specified string centered, if width is less than the width of the string is returned directly to the string, otherwise fillchar to fill.
Examples
The following example shows the center () instance method:
#!/usr/bin/python3 str = "[www.w3big.com]" print ("str.center(40, '*') : ", str.center(40, '*'))
Examples of the above output results are as follows:
str.center(40, '*') : ************[www.w3big.com]************