I have been learning Python for a while and the raise
function and assert
are (what I realised is that both of them crash the app, unlike try - except) really similar and I can't see a situation where you would use raise
or assert
over try
.
So, what is the difference between Raise, Try and Assert?
assert cond, "text"
is expanded to something like
if cond == False:
raise AssertionError("text")
use assert because it is more readable.