+ 1

Can assign variable to error type in python ?

so in future i can use that variable in tha place of the error type like i had tried in balow code but is showing error. try: ZeroDivisionError=zero print("Hello") print(1 / 0) except Zero: print("Divided by zero") finally: print(10/1)

23rd Jul 2020, 1:22 PM
PawanK
PawanK - avatar
3 Réponses
+ 5
Yeah that's possible but you have to assign the other way around: zero = ZeroDivisionError now it will work
23rd Jul 2020, 1:27 PM
Bagon
Bagon - avatar
+ 2
Yep you can all of these are objects so you can store them, fixed your code here https://code.sololearn.com/chzFNaNCi4PQ/?ref=app
23rd Jul 2020, 1:28 PM
Sousou
Sousou - avatar
+ 1
Bagon Sousou thanks
23rd Jul 2020, 3:13 PM
PawanK
PawanK - avatar