Unlike languages like C++ or Java that use curly braces `{}` to define code blocks, Python enforces significant indentation (typically 4 spaces) following a colon (`:`):
A. The `if-elif-else` Multi-Way Selection
marks = float(input("Enter percentage: "))
if marks >= 90:
grade = "A+"
elif marks >= 75:
grade = "A"
elif marks >= 60:
grade = "B"
elif marks >= 40:
grade = "C"
else:
grade = "F"
print(f"Verified Grade: {grade}")
B. Short-Circuit Logical Evaluation
Python evaluates compound Boolean expressions using short-circuit logic:
- In `A and B`: If `A` evaluates to `False`, Python immediately returns `False` without evaluating `B` (saves execution time and prevents runtime crashes like division by zero: `x != 0 and (10 / x) > 2`).
- In `A or B`: If `A` evaluates to `True`, Python immediately returns `True` without evaluating `B`.