T
T
TanderOFF2021-04-10 20:31:04
Python
TanderOFF, 2021-04-10 20:31:04

F-string: invalid syntax in format?

If you leave if and else, then everything works fine, how to do something else, you could add elif

name=f"{counter}  {'em1' if counter == 1 'em2' elif counter == 2 'em3' elif counter == 3 else 'em4'}"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-04-10
@TanderOFF

No, the ternary operator does not support elif. You can fence constructions of the form a if b else c if e else d, but it’s better not to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question