in general to explain it to understand:

precondition, postcondition, class invariant: are a series of checks a computer programming language interpreter makes.

pre-condition checks that the types of arguments are correctly matching the types of parameters.
post-condition checks that the return type is correctly matching the destination variable data type.

generally, the pre-condition is the expected situation about the input.
and, the post-condition is the expected situation about the output in the destination.

usually, there is also A Note about “class invariant” (data type) invariant parameters and return value;

Frequently we use a general data type, the built-in precondition that checking of type is not enough. in that note it is advised when appropriate to check the data itself in the beginning:


def show_hour(hour):
    assert hour<24 and hour>=0,"hour should be 0-23" # checking data of general type parameters

Other ways to raise an error in python:

Some documentation from a compiler to show some origin:

It is possible to play with it with python 3:

179 words