Str.center will return a centered string of length width and padding is done using the specified fill character.
Syntax of Str.center:
center(width, fillchar=' ') By default it is space (if not filled anything)
a='Apple'
a.center(9)
Output:
' Apple '
It adds spaces to both side. Similarly we can pad any char by filling it in fill char.
Example-2: By filling character.
a='Apple'
a.center(9,'-')
Output:
'--Apple--'
[…] Str.Center:It will return padded centered […]