← 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?
- A.assert is slower than if
- B.assert cannot have a message
- C.Python skips assert statements when run with -O, so the check disappears
- 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 →