__debug__
Built-in ConstantPython 2.0+Intermediate
True under normal execution; False when run with -O flag
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
# Triggering and catching __debug__ try: raise __debug__("example error") except __debug__ as e: print(f"Caught __debug__: {e}") print(f"Type: {type(e).__name__}")
__debug__ is raised when true under normal execution; false when run with -o flag. Always catch specific exceptions rather than bare except clauses.
Try in PlaygroundTags
builtinconstantcore