The assert command in Python can be used to determine whether the value of the variable is consistent with the expected value
The sample program is as follows:
a = 4
assert a==4
print("There is no mistake")
# assert a==3
print("That's ok")
At this time, when the second assert function is used, comment it out first, because the actual value of a is consistent with the size of 4, so the program executes normally and completely.
But if the second assert function is uncommented:
a = 4
assert a == 4
print("There is no mistake")
assert a == 3
print("That's ok")
Then the program will report an error and will not execute subsequent codes
The execution results are as follows:
The above is a brief introduction to the assert function.