+ 1
What does âassert do??
Iâm in the middle of the python course and k e of the lessons is assertions, but I just donât really understand what it is and what it does. Please help!!
4 RĂ©ponses
+ 3
I think, this article here explains it quite well:
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-assert-statement/
+ 2
You can check for some condition to be True.
If it's True, nothing will happen, the program will go on.
If it's False, an AssertionError will occur, stopping the program.
If you write...
assert 1==2
... anywhere in your program, it will stop executing because the result is False.
However, if you write...
assert 1==1
... nothing will happen, the program just runs on, because the result is True.
0
Okay thank you, just one question, how would this be useful in a program?
0
Thank you!