English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The center() method returns a new string with the original string centered and filled with spaces to the length width.
The syntax of the center() method is:
string.center(width[, fillchar])
The center() method takes two parameters:
width- The 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("The filled string: ", new_string)
The output when running the program is:
The filled string: Python is awesome
string = "Python is awesome" new_string = string.center(24, ''*) print("The filled string: ", new_string)
The output when running the program is:
The filled string: ***Python is awesome****