Home > Enterprise >  output centered text using F-strings with dictionaries
output centered text using F-strings with dictionaries

Time:07-04

I want to output values from my dict using f string but if I use that codeprint(f"{*excel_values['object']}"), I have error SyntaxError: can't use starred expression here. How can i fix this problem? UPD: I have to use f string because i want to center values using print(f'{text: ^55}')

CodePudding user response:

error say you can't use * expression here. remove the star (*) expression

print(f"{excel_values['object']}")

CodePudding user response:

Try using the format method

print('{:^55s}'.format(*excel_values['object']))

By this way, you could center the text without using f-string

  • Related