Description Of Python Center() Method
The center(n , 'char') character string method in Python returns a centered string in a string of length n by completing the right and left of the string with the 'char' character chosen as a parameter. The padding 'char' character is optional and in the ignored case the default padding is the space character.
Center() Method Parameters & Syntax
Syntax
string.center(width[, fillchar])
Parameters
- width: This is the total width of the string.
- fillchar: This is the fill character.
Example (filling using the '*' character)
s="Python Programming"
s = s.center(30, '*')
print(s)
# output: '******Python Programming******'
Example (filling using space character)
s="Python"
s = s.center(15)
print(s)
# output: ' Python '
Younes Derfoufi
my-courses.net
my-courses.net
[…] capitalize (): capitalize the first letter of the string 2. center (width, fill): returns a string filled with spaces with the original string centered on the total width […]
[…] capitalize (): capitalize the first letter of the string 2. center (width, fill): returns a string filled with spaces with the original string centered on the total width […]