What is the expected behavior of the following code?
What is the expected behavior of the following code?
D
ValueError s = '2A' try: n = int(s) except ValueError: n=2 except ArithmeticError: n=1 except: n=0 print (n)
Can anyone explain what is happening here? why is the answer 2?
because it causes ValueError. you cannot cast the input to int because there is a character within
D. it outputs 2