What are assertions? Can somebody explain it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

What are assertions? Can somebody explain it?

Assertion

13th Oct 2018, 3:09 PM
🔥EACY🔥
🔥EACY🔥 - avatar
2 Answers
+ 2
An assertion is a command that assumes something as necessarily true, then raises an error otherwise. It's useful for debugging - you insert an assertion in your code where you expect, for example, a variable to have a certain value. If it hasn't, your code fails with a clear message, instead of running until something goes wrong and you have to investigate why.
13th Oct 2018, 5:40 PM
Emerson Prado
Emerson Prado - avatar
+ 3
Thanks for explaining
13th Oct 2018, 8:24 PM
🔥EACY🔥
🔥EACY🔥 - avatar