Python: String Formatter Align center
Use the new-style format
method instead of the old-style %
operator, which doesn't have the centering functionality:
print('{:^24s}'.format("MyString"))
You can use str.center()
method.
In your case, it will be: "MyString".center(24)