Python assert Keyword

For debugging. This 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.

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