+ 3
About asserts
try: print(1) assert 2+2==5 except AssertionError: print(3) except: print(4) If I will run this code, the result is 3. What I think is that assert must take false and must not run the except. Or it is running except because assert took false?
10 Respuestas
+ 8
Why is everyone smarter than me :(
+ 7
If the assertion returns False it runs the AssertionError clause if one exists, if you only had the general except clause then it would print 4. If the assertion returns True, no exceptions will be called (:
+ 3
Answer is 3
+ 1
Quantr Post your code, but it's probably a syntax error as stated.
+ 1
3
+ 1
3
+ 1
3
0
3
- 1
when i tryed this code it said syntax error could be because i changed the print variable?
- 2
try:
print(1)
assert 2+2==5 == > This is False , of assert occurs
except AssertionError: ==> but we are handling the asset exception, so it
will come here and print 3, if
except AssertionError: was not there , then the
program would have terminated after printing
1
print(3) == > Print 3
except: == > This will never be called
print(4)