Python · Debugging & Testing

Running a script with python -O myapp.py, what happens to every assert statement in the code, and what does __debug__ equal?

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Debugging & Testing

What's the core difference in how doctest vs unittest define their test cases, and one practical trade-off?
You ship an API and use this to reject bad input: ``` def withdraw(amount): assert amount > 0, "must be positive" ... ``` Why is this a real security bug in production?
What is the difference between ``` assert x == y ``` and ``` self.assertEqual(x, y) ``` in a failing unittest?
A unittest class has this method. After running it with `python -m unittest`, the report says "Ran 0 tests". Why? ``` class MyTest(unittest.TestCase): def checkCalc(self): self.assertEqual(fac(5), 120) ```
In unittest, when do setUp and tearDown run relative to your test methods?
You want to assert that calling `fac(-1)` raises `ValueError`. What does this do, and why is it the wrong way? ``` self.assertRaises(ValueError, fac(-1)) ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play