The third one that @
Axel_Erfurt show can also be more elegant.
>>> print(f'{" "*5} test')
test
>>> print(f'{"test":>10}')
test
So @
leodavinci1990 the old string formatting
%s
should not be used anymore,use
f-string
>>> h = 'hello'
>>> w = 'world'
>>> print(f'{h:^10}{w:>10}')
hello world
>>> print(f'{h:<10}{w:<10}')
hello world
>>> print(f'{h:^10}{w:^10}')
hello world
>>> print(f'{h:>10}{w:>10}')
hello world
>>> # f-strings support any Python expressions inside the curly braces
>>> a, b = 5, 7
>>> f'{a}/{b} = {a/b:.2}' # limit to two decimal places
'5/7 = 0.71'
>>> for word in 'f-strings are awesome'.split():
... print(f'{word.upper():~^20}')
~~~~~F-STRINGS~~~~~~
~~~~~~~~ARE~~~~~~~~~
~~~~~~AWESOME~~~~~~~