33 lessons
Python · Module 2Module material

Control Flow interview questions

25 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.

Conditions

  1. How does Python know where an if block ends?●
  2. Which values are falsy in Python?●
  3. What is wrong with if day == "Saturday" or "Sunday":?●●
  4. What is the difference between a chain of if/elif and a sequence of separate if statements?●●
  5. Why does the order of the conditions in an elif chain matter?●●
  6. What is the conditional expression, and when should you not use it?●
  7. What does x = name or "Guest" do, and how does it differ from x = name if name else "Guest"?●●
  8. How can a condition avoid dividing by zero?●●
  9. When would you use match instead of if/elif?●●
  10. What is the most common mistake with match?●●

while loops

  1. When do you use while rather than for?●
  2. How do you make sure a while loop terminates?●
  3. Can a while loop's body run zero times? When exactly does the loop stop?●●
  4. What is a sentinel value?●●
  5. What is the walrus operator, and what goes wrong without brackets?●●

for loops

  1. What is an iterable?●
  2. What does range return, and why is len(range(10**12)) fast?●●
  3. Why is for i in range(len(items)): discouraged?●●
  4. What does zip do when its arguments have different lengths?●●
  5. After for steps in week: finishes, does steps still exist? Does assigning to the loop variable inside the body change the loop?●●
  6. How many times does a nested loop's inner body run?●●

break, continue and else

  1. What is the difference between break, continue and pass?●
  2. Does break in a nested loop leave both loops?●●
  3. When does a loop's else block run?●●
  4. When is while True: with break the right form?●●

Directory listings

  • SchoolWhool on Siteefy