AssertionError

noun

say it: “uh-SUR-shun AIR-er” /əˈsɝʃən ˈɛrər/

The error Python gives when a check written with assert turns out to be false, with the message the check carries.

What is an AssertionError in Python?

An AssertionError is the error Python raises when an assert statement's condition is False. It carries the message written after the comma, so the error says what went wrong; when the condition is True, nothing happens.

assert readings["humidity_pct"].between(0, 100).all(), "humidity must be 0 to 100"
# AssertionError: humidity must be 0 to 100

In a sentence

  • “The cleaning stopped with an AssertionError: humidity must be 0 to 100.”
  • “An AssertionError means a check you wrote found something false.”

Level: Apprentice · More Python terms at this level

Updated