Can you explain me the concept of assertion and its use in python | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 3

Can you explain me the concept of assertion and its use in python

18th Apr 2017, 7:37 AM
Aryan
Aryan - avatar
6 Réponses
+ 9
No I can't, I've never heard of it...
18th Apr 2017, 9:40 AM
Ahri Fox
Ahri Fox - avatar
+ 6
Umm, I think you may be referring to C/C++. Those are the only languages that I know implement assertions.
18th Apr 2017, 10:13 AM
SoraKatadzuma
SoraKatadzuma - avatar
+ 4
You could think of assertion as "make sure this statement is true" It can be used to prevent making operations over wrong data
18th Apr 2017, 11:33 AM
spcan
spcan - avatar
+ 1
You need to understand the difference between assertion with try/except. Exceptions address the robustness of your application while assertions address its correctness. Assertions should be used to check something that should never happen while an exception should be used to check something that might happen (something in which you don't have control like user input). NOTE: The thumb rule is that use assertions when you are trying to catch your own errors and exceptions when trying to catch other people's errors.
16th Nov 2018, 3:31 AM
Tamoghna Saha
0
simply to check if the code is doing as u expected. use it when u can't find the error by urself
31st Mar 2018, 2:44 PM
knock home
knock home - avatar
0
An assertion is a sanity-check that you can turn on or turn off when you have finished testing the program. An expression is tested, and if the result comes up false, an exception is raised. Assertions are carried out through use of the assert statement.
7th May 2019, 5:10 PM
Mayank Arora