PythonStringcenter
rjust

centerString

isdigit

Returns the string centered in a field of given width.

Syntax

str.center(width, fillchar?)

Example

Enter values below to update the example in real time.

print
center
text = "hi"
print(text.center(10))        # "    hi    "
print(text.center(10, "-"))   # "----hi----"