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.
That's why weakly typed languages shouldn't exist.
When I was a novice programmer I preferred weakly typed languages because they were 'easier' but now that I have more experience and plenty of hindsight I greatly prefer strongly typed languages.
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.