331-2 - Python Data Analysis Basics - Calculating Artist Age


I used isinstance rather than type, is there any reason why one is better than the other. Here is my code:

ages =
for row in moma:
date = row[6]
birth = row[3]
if isinstance(birth,int):
age = date - birth
age = 0

final_ages =
for age in ages:
if age > 20:
final_age = age
final_age = ‘Unknown’

It seemed to return the correct result.

Hi @jdj,

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.

1 Like