To test an expression in a program code, _____ statement in python is used.
To test an expression in a program code, _____ statement in python is used.
Solution
✅ Correct Option: 3
The assert statement tests an expression (a condition). If the expression is True, the program continues normally. If it is False, Python raises an AssertionError, optionally with a message, e.g. assert x > 0, "x must be positive".
Option 1: finally is a block that runs after try/except whether or not an error occurred. It does not test a condition.
Option 2: raise is used to throw an exception deliberately, without testing any expression.
Option 4: catch is not a Python keyword. It belongs to Java and C++, whereas Python uses except.
Related questions:
2025: 21 May Shift 1
2026: 23 May Shift 1