+ 3
What is the different between assertions and raising
3 odpowiedzi
+ 6
Raise is one tool for your program's exception handling at runtime, while assert should be used as a debugging tool only.
Depending on how and where your script is gone, assert might be deactivated; so you can't have your program flow depend on it.
+ 5
Tibor Santa
HonFu
Thanks ❤
+ 3
assert will check if a condition is True (that can be verifying if the value of a variable is in the expected range or what is the type of the variable) and if it evaluates to False, then an AssertionError is raised automatically.
raise can trigger any type of error, whenever you need to create an exception in your code (and possibly catch it later in the try/except block). It can be used to alter the flow of execution in your program.