I cannot seem to find a good simple explanation of what python does differently when running with the -O or optimize flag.
As answered in python optimization mode:
python -O does the following currently:
__debug__
to False (which by default is True)and when called as python -OO
I don't know why everyone forgets to mention the __debug__
issue; perhaps it is because I'm the only one using it :) An if __debug__
construct creates no bytecode at all when running under -O
, and I find that very useful.