Let us look at the example:
1 2 3 4 5 6 7 8 9 10 |
def main(): a, b = 8, 89 # conditional flow uses if, elif, else if(a < b): print('a is less than b') else: print('a is greater than b') if __name__ == "__main__": main() |
This will print a is less than b. Here, if we make a and b equal that also it will print a is greater than b
So let is add the condition to check if both are equal. We do it by elif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def main(): a, b = 8, 80 # conditional flow uses if, elif, else if(a < b): print('a is less than b') elif(a == b): print('a is equal to b') else: print('a is greater than b') # conditional statements let you use "a if C else b" if __name__ == "__main__": main() |
Note: There is no equivalent to switch case in python
Python short conditional statement
1 2 3 |
a,b = 5,79 st = "a is less that b" if(a<b) else "x is greater the or same as y" print st |
Similar to ternirary oerator or php/ javascript