Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ternary using pass keyword python

I have a working conditional statement:

if True:
    pass
else:
    continue

that I would like to turn it into a ternary expression:

pass if True else continue

However, Python does not allow this. Can anyone help?

Thanks!

like image 792
Kodiak North Avatar asked Oct 20 '25 11:10

Kodiak North


1 Answers

pass and continue are a statements, and cannot be used within ternary operator, since the operator expects expressions, not statements. Statements don't evaluate to values in Python.

Nevertheless, you can still shorten the condition you brought like this:

if False: continue
like image 67
Israel Unterman Avatar answered Oct 23 '25 00:10

Israel Unterman