+ 3

What is the different between assertions and raising

4th Feb 2019, 8:59 AM
Obada Alathamneh
Obada Alathamneh - avatar
3 Réponses
+ 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.
4th Feb 2019, 10:45 AM
HonFu
HonFu - avatar
+ 5
Tibor Santa HonFu Thanks ❤
4th Feb 2019, 12:13 PM
Obada Alathamneh
Obada Alathamneh - avatar
+ 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.
4th Feb 2019, 10:09 AM
Tibor Santa
Tibor Santa - avatar