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:
Step 1: Understand Python's all() function usage
all() takes an iterable of boolean expressions; correct syntax uses '==' for comparison inside a generator expression.
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.
Final Answer:
all(cell == 'X' for cell in row) -> Option C
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()
Master "Design — Tic-Tac-Toe Game" in LLD
9 interactive learning modes - each teaches the same concept differently