Yes, but you must pass them as arguments to format , and then refer to them wrapped in {} , as well as the name of the argument itself:
print('\n{:^{display_width}}'.format('some text here', display_width=display_width))
Or shorter, but slightly less explicit:
print('\n{:^{}}'.format('some text here', display_width))
source share