The if else statement in Python can be incredibly helpful when you need to perform certain actions based on certain conditions. But just like with anything else, there are right and wrong ways to do it. In this article, we’ll go over how and when to use the if else statement in Python, plus some examples of where you might use it. I highly recommend you get the “Python Crash Course Book” to learn Python.
Example 1: if else in Python
age = 70 if age < 60: print("Young Man") else: print("Old Man")
marks = int(input("Enter Your Marks = ")) if marks < 33: print("Fail") else: print("Pass")
Enter Your Marks = 45 Pass
age = float(input("Enter Your Age = ")) if age < 18: print("You are kid") else: print("You are adult")
Enter Your Age = 22 You are adult
You can also find tutorials related to advance skills from AiHints.