+ 1

Can someone properly explain "assert"?

I recently learned the module about the "assert" command in Python and I still can't figure out the difference between that and other errors. What's the difference? Does it cause an assertion error even if it occurs a lot later in the program? I'm not sure I understood anything at all...

4th Mar 2017, 1:35 AM
Omri Levin
Omri Levin - avatar
2 Respuestas
+ 2
Ensures the condition is true or raises an AssertionError. Useful during debugging/testing and often replaced with an if statement for release code. https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/assertions_in_python.htm https://docs.python.org/2.0/ref/assert.html
4th Mar 2017, 2:09 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thank you! I did wonder why not simply use if. Guess it all lies in the original purpose
4th Mar 2017, 2:26 AM
Omri Levin
Omri Levin - avatar