Loading

Quipoin Menu

Learn • Practice • Grow

python / Conditional Statements
interview

Q1. What are the conditional statements in Python?
Python uses if, elif, and else for conditional branching. Syntax:
if condition1: # block elif condition2: # block else: # block
Conditions are any expression that evaluates to boolean.

Q2. How does the ternary operator work in Python?
Python has a ternary operator for concise conditional expressions:
value_if_true if condition else value_if_false
Example:
x = 10 if a > b else 5

Q3. What is the difference between if and elif?
if checks a condition; elif (else-if) checks another condition only if previous conditions were false. Multiple elif can be chained. else runs if none of the previous conditions are true. Only one block executes.

Q4. Can you use logical operators in conditions?
Yes, Python supports and, or, not for combining conditions. Example:
if age >= 18 and age < 65: print("Adult")
Short-circuit evaluation is applied.

Q5. What is the pass statement used for?
pass is a null operation; it does nothing. It's used as a placeholder when syntax requires a statement but no action is needed, e.g., in empty functions or classes, or to avoid errors in conditional blocks.