Python trinary operator
Since python's list value with index 0 and 1 can be accessed using True-->1
and False-->0, same thing can be used to derive trinary operator "?:" from C.
z = "Print when x is False"
y = "Print when x is True"
x = True
print [z, y ][bool(x)] # prints "Print when x is True"
And in python works bit different way..
To evaluate expression which contain "and" all the values in expression should be
true so, python checks all value and returns the very last value(right most value itself)
In case of expression containing 'or' any one of the value needed to be evaluated
to true, so when python finds one value as true same value will be returned,
ie. leftmost value in the expression.
x = "extra"
y = "perfect"
print x and y # prints "perfect"
print x or y # prints "extra"
How we are going to make use of this implementation? we will derive trinary operator "?:" from C
print bool(x) and y or z