assertions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

assertions

HI everyone, I am not quite sure, after a lesson on assertions, still what they are used for and why they are used. I am not sure how they work with other statements e.g. print(0) assert "h" != "w" print(1) assert False print(2) assert True print(3) as used in the lesson. I understand that they are used to catch errors. but after that am not sure what they do with that. Can someone answer all these questions I have, please, as well as talk through this example code? Many thanks!

13th Mar 2021, 10:14 AM
Kamil Hamid
Kamil Hamid - avatar
2 Answers
+ 1
assert check if the statement is True. If its true it returns nothing, else it returns AssertionError https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_keyword_assert.asp but to build solid code testing, Unit Testing module should be used https://www.datacamp.com/community/tutorials/unit-testing-python
13th Mar 2021, 10:23 AM
iTech
iTech - avatar
+ 1
Ah, thank you!
13th Mar 2021, 10:25 AM
Kamil Hamid
Kamil Hamid - avatar