🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Exceptions in Depth: all 10 questions

Quiz: Exceptions in Depth · Question 9 of 10

Why should assert not be used to validate user input?

Why should assert not be used to validate user input?

  1. A.assert only works on numbers
  2. B.assert always raises an error
  3. C.Assertions are skipped when Python runs with the -O option
  4. D.assert cannot have a message
Answer & explanation

Correct answer: Assertions are skipped when Python runs with the -O option

Input checks must always run, so use if and raise instead.

Can you get the rest right without peeking?

Take the timed Quiz: Exceptions in Depth quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →