What is assert in python?

The assert statement in python is used in debugging code. It is used to show error if we want a condition to be always true. We can write an assertion error message to show that what is the error.
syntax:-
assert condition, "assertion error message"
e.g.,
x=2 y=0 a=x/y assert y!=0, "cannot divide by 0"

This is all about assert in python.
Subscribe
Login
Please login to comment
0 Discussion