Python Control Flow Functions Interview Questions
Python Control Flow Functions Interview Questions
Answer: Local variables are declared inside functions and accessible only there.
Global variables are declared outside any function and accessible throughout the module.
Answer: Operator precedence determines the order in which operators are evaluated.
Example: *, / have higher precedence than +, -.
Use parentheses to override it.
🔹 Control Structures
10. Q: Explain if-else conditions in Python.
Answer: Example:
if x > 0:
print('Positive')
elif x == 0:
print('Zero')
else:
print('Negative')
11. Q: How do you write loops in Python?
While loop:
i=0
while i < 5:
print(i)
i += 1
Answer: Python doesn't have switch-case. Use if-elif-else or match-case (Python 3.10+).
🔹 Functions
15. Q: What are functions in Python?
Answer: Functions are reusable blocks of code that perform a specific task.
Answer: Decorators modify the behavior of a function without changing its code.
Example:
@decorator
def func(): pass
Answer: A generator yields values one at a time using `yield` and maintains state between
calls.
Example:
def gen():
yield 1
yield 2