Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question