+ 1

Assertion in Python

Why use assertion when you can just create an if statement?

19th Nov 2019, 10:34 AM
vrick
vrick - avatar
3 Respuestas
+ 5
someone said something along the lines of “if statements catch user errors, assertions are used to catch your own” i dont use them myself and im new to python but it sounds good to me
19th Nov 2019, 12:38 PM
꧁༺ Jenspi ༻꧂
꧁༺ Jenspi ༻꧂ - avatar
+ 2
Assertions are basically a debugging tool. Depending on how your Python code is run, assertions may be ignored completely (basically like comments), and if your code relies on them working, you can probably see how this will lead to trouble. So to decide what happens in your code, only rely on if and else.
19th Nov 2019, 2:57 PM
HonFu
HonFu - avatar
0
You're looking more like a pro...
19th Nov 2019, 10:42 AM
ztonaz
ztonaz - avatar