Shwiby Shwiby - 1 year ago 83
Java Question

Equivalent for ? in Java for Python?

In java, I use the

variable = something == 1 ? 1 : 0


function all the time. Is there an equivalent function in python?

Answer Source

In Python, that operator reads slightly differently - more like English. The equivalent to your Java statement in Python would be:

variable = 1 if something == 1 else 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download