assert - For debugging

Asserts that something is True.

Example

Python
name = 'Joe'
assert(name != 'Marc')
print("Now we know that it's not Marc")

Output

Now we know that it's not Marc

If the assertion fails, Python will throw an Assertion exception.

Example

Output

File "test.py", line 2, in <module>
assert(name != 'Joe')
AssertionError

Notes

Assertion expressions can be chained together with commas.

Example

Python
name = 'Joe'
assert(name != 'Marc', name != 'Jane')
print("It's not Marc or Jane")

Output

It's not Marc or Jane