+ 1

What does assertion means ?

Plz give the answer in simple word as you possible

5th Mar 2019, 1:50 PM
Shubham singh
Shubham singh - avatar
2 ответов
+ 5
Assertion means that you assume that a statement is true and if it isn't, an exception will be raised (=there will be an error). Example: n = 5 assert n < 10 # this is true, so nothing will happen assert n > 10 # this is false, so the program will show an error It is almost the same as an if statement: if n < 10: # do nothing pass if n <= 10: raise ValueError # raise an exception
5th Mar 2019, 2:27 PM
Anna
Anna - avatar
+ 1
assert is like an if, but where an if returning True will execute a block of code, an assert statement returning True will do nothing. An if returning False will not execute a block of code, an assert returning False will throw an error. assert True #code executes normally assert False #AssertionError raised
5th Mar 2019, 2:30 PM
Russ
Russ - avatar