World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITian's, only for AI Learners.
Download our e-book of Introduction To Python
4 (4,001 Ratings)
218 Learners
Sulochana Kamshetty
5 months ago
>>> x, y = 7, 8
>>> if x>y:
print("x")
else:
print("y")
>>> x, y = 5, 6
>>> print("x" if x> y else "y")
y
>>> def find_max(a,b):
return a if (a>b) else b
>>> find_max(5, 6)
>>> a, b = random(), random()
>>> {False: f"b:{b}", True: f"a:{a}"}[a>b]
'a:0.8089581560973976'
# We can interchange the key-value pair -
>>> {True: f"a:{a}", False: f"b:{b}"}[a>b]
>>> (lambda: f"a:{a}", lambda: f"b:{b}")[a>b]()
>>> from random import random
>>> x = random()
>>> "Less than zero" if x<0 else "between 0
and 5" if a>=0 and a<=5 else "Greather than five"