AI engineering glossary · Python advanced

What is assertion?

Assertion: A statement that checks a condition is true and raises an AssertionError if not. In tests it verifies expected results; in code it documents assumptions during development. Assertions can be switched off with the -O flag, so they should not validate user input.

Level: beginnerTopic: Python advanced

Assertion: an example

assert len(rows) > 0, 'no data loaded' stops with the message if rows is empty.

Related terms

More Python advanced terms

Where you learn it

Assertion is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.