I'm just starting to learn my way around classes now and I came across something I don't understand. Let's say I have a class...
class Area(object):
def __init__(self, name, items):
self.name = name
self.items = items
Now if I initiate an instance of Area this way:
impala = Area("Impala", ["shotgun", "salt"])
and then call on a variable, say:
print impala.items
it works just fine. However, if I try to initiate it this way:
class impala(Area):
def __init__(self):
self.name = "Impala"
self.items = ["shotgun", "salt"]
and then try to do the same thing it gives me an error: "type object 'impala' has no attribute 'items'"
Could someone please tell me what I'm doing wrong in the second example and why it's happening?
class impala(Area)does not create an instance ofArea. It defines a subclass ofAreacalledimpala.