C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: Assert() only has an effect when __debug__ is true. We can disable __debug__ with a command-line parameter.
So: If the two values add up to 110, an assertion occurs. Otherwise nothing happens.
Command lines: The first command line uses the "O" option. This means the assertion is optimized out of the program.
And: The second command line uses no special options, so the assert is left in the program and triggered.
Python program that uses assert
value = 10
value2 = 100
# Assert if this expression is not true.
assert(value + value2 != 110)
print("DONE")
Command line:
C:\pypy3-2.4.0-win32\pypy.exe -O C:\programs\file.py
Output
DONE
Command line:
C:\pypy3-2.4.0-win32\pypy.exe C:\programs\file.py
Output
Traceback (most recent call last):
File "C:\programs\file.py", line 8, in <module>
assert(value + value2 != 110)
AssertionError
Options:
-O : skip assert statements
Quote: The current code generator emits no code for an assert statement when optimization is requested at compile-time.
Simple statements: python.org