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:

like:

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: https://stackoverflow.com/a/17560982/466363

Some documentation from a compiler to show some origin:
https://docs.oracle.com/cd/E19683-01/806-7930/assert-13/index.html
https://en.wikipedia.org/wiki/Class_invariant

It is possible to play with it with python 3:
https://stackoverflow.com/questions/12151182/python-precondition-postcondition-for-member-function-how/12151531#12151531

179 words