Python has an if operator '?' like Java?
Example in Java:
String res = (2 > 1) ? "yes" : "no";
Python has an if operator '?' like Java?
Example in Java:
String res = (2 > 1) ? "yes" : "no";
No, Python doesn't have ?:
operator but if
/else
can be used to achieve the same result on one line:
res = 'yes' if 2 > 1 else 'no'