Bird
0
0

Which of the following is the correct syntax to check if all elements in a row are equal to 'X' in Python?

easy🧠 Conceptual Q3 of 15
LLD - Design — Tic-Tac-Toe Game
Which of the following is the correct syntax to check if all elements in a row are equal to 'X' in Python?
Aall(row == 'X')
Brow.all('X')
Call(cell == 'X' for cell in row)
Dall(cell = 'X' for cell in row)
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python's all() function usage

    all() takes an iterable of boolean expressions; correct syntax uses '==' for comparison inside a generator expression.
  2. Step 2: Identify correct syntax

    all(cell == 'X' for cell in row) uses 'all(cell == 'X' for cell in row)' which is correct; all(cell = 'X' for cell in row) uses assignment '=' which is invalid in expressions.
  3. Final Answer:

    all(cell == 'X' for cell in row) -> Option C
  4. Quick Check:

    all() with comparison uses '==' [OK]
Quick Trick: Use '==' inside all() generator, not '=' [OK]
Common Mistakes:
MISTAKES
  • Using '=' instead of '=='
  • Calling all() on non-iterable
  • Wrong method syntax like row.all()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes