Your question is really ambiguous.
You say you want the parent class Fruits
to contain objects of type Orange
/Apple
etc.But you also say depending on what class got created you wanted to do something.
*If the conditions match... . (What conditions??) you haven't specified what conditions. Based on what you've provided I have an interpretation of what the answer should be.
class Fruit(object):
color = None
values = None
nature = None
def __init__(self, color, values, nature):
self.color = color
self.values = values
self.nature = nature
class Orange(Fruit):
color = "Orange"
def __init__(self, values, nature):
super(Orange, self).__init__(self.color, values, nature)
class Apple(Fruit):
color = "Red"
def __init__(self, values, nature):
super(Apple, self).__init__(self.color, values, nature)
# a = Fruit("Green", (3,4), "Organic")
l = []
l.append(Fruit("Green", (3,4), "Organinc"))
l.append(Orange((3,4), "Non Organic"))
l.append(Apple((4,3), "Organic"))
print l
for f in l:
if type(f) is Orange:
print "Found an orange"