1. Home
  2. Data Science
  3. Python
  4. What does the 'assert' statement in Python do?

Added 10 Feb 2024

What does the 'assert' statement in Python do?

  1. It raises an exception if a condition is true Correct answer
  2. It prints a message to the console
  3. It terminates the program
  4. It is used to define a new variable

Correct answer

A. It raises an exception if a condition is true

16 views

MCQSEXAM

Explanation

The 'assert' statement in Python is used to test whether a given condition is true. If the condition evaluates to false, it raises an AssertionError with an optional error message.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs