English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The center() method returns a new string that is centered and filled with spaces to the length width.
center() method syntax
string.center(width[, fillchar])
center() method takes two parameters:
width- Length of the filled string
fillchar (optional)-Fill character
The fillchar parameter is optional. If not provided, a space is used as the default parameter.
The center() method returns a string filled with the specified fillchar. It does not modify the original string.
string = "Python is awesome" new_string = string.center(24) print("Filled string: ", new_string)
When running the program, the output is:
Filled string: Python is awesome
string = "Python is awesome" new_string = string.center(24, ''*) print("Filled string: ", new_string)
When running the program, the output is:
Filled string: ***Python is awesome****