>A Byte of Python

The assert statement

The assert statement is used to assert that something is true. For example, if you are very sure that you will have at least one element in a list you are using and you want to check this and make sure an error is raised if it is not true, then, the assert statement is ideal in this situation. When the assert statement fails, an AssertionError is raised.

>>> mylist = ['a']
>>> assert len(mylist) >= 1
>>> mylist.remove('a')
>>> mylist
[]
>>> assert len(mylist) >= 1
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AssertionError
>>>