This could obviously be done with an if-elif-else logic, but I wish to ask for a better - more pythonic way to implement it. eg.
a,b = 14,73
if a>b:
print('a')
elif a<b:
print('b')
else:
print('a=b') #not_required_though
This could obviously be done with an if-elif-else logic, but I wish to ask for a better - more pythonic way to implement it. eg.
a,b = 14,73
if a>b:
print('a')
elif a<b:
print('b')
else:
print('a=b') #not_required_though
You can do if else in one line
print('a' if a>b else 'b')
or you can also assign it to variable
res = 'a' if a>b else 'b' if b>a else 'a==b'