+ 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!!

15th May 2022, 8:41 PM
Gabriel Burchfield
4 odpowiedzi
+ 3
15th May 2022, 8:53 PM
HonFu
HonFu - avatar
+ 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.
15th May 2022, 8:50 PM
HonFu
HonFu - avatar
0
Okay thank you, just one question, how would this be useful in a program?
15th May 2022, 8:51 PM
Gabriel Burchfield
0
Thank you!
15th May 2022, 10:15 PM
Gabriel Burchfield