I used isinstance rather than type, is there any reason why one is better than the other. Here is my code:
for row in moma:
date = row
birth = row
age = date - birth
age = 0
for age in ages:
if age > 20:
final_age = age
final_age = ‘Unknown’
It seemed to return the correct result.
For the scope of this task, there is no difference which of them to use: both are correct approaches.
In general, however, there is a difference:
isinstance() takes into account class inheritance, which means that a subclass of a class is an instance of that class. Instead,
type() requires an absolute identity of the types and doesn’t take into account subclasses. In this article you’ll find a good example of their difference.