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

Quiz: Testing Python Code · Question 2 of 10

Why should you not use assert to validate user input in a real program?

Why should you not use assert to validate user input in a real program?

  1. A.assert is slower than if
  2. B.assert cannot have a message
  3. C.Python skips assert statements when run with -O, so the check disappears
  4. D.assert only works inside unittest
Answer & explanation

Correct answer: Python skips assert statements when run with -O, so the check disappears

Use if and raise ValueError for checks that must always run.

Can you get the rest right without peeking?

Take the timed Quiz: Testing Python Code quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →