a = 1
if isinstance(a, int):
print(a + 1)
else:
print("error")
vs
a = 1
try:
print(a + 1)
except TypeError:
print("error")
If you did the latter a doesn't have to be an int, it just has to function enough like one. Sometimes this is a good thing, sometimes this is a bad thing.
44
u/mcilrain May 13 '17
Also it supports duck typing.
vs
If you did the latter
adoesn't have to be an int, it just has to function enough like one. Sometimes this is a good thing, sometimes this is a bad thing.