Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question