Python Ternary Operator


Python Ternary Operator. Let’s see how to use ternary operator in Python.

Assuming this is your Python code :

value = True
if value:
    print "Value found"
else:
    print "No value found"

Here is how you can use ternary operator for the above code,

value = True
msg = "Value found"  if value else  "No value found"
print msg