class BasketballGame(object):def __init__(self, teams):self.teams = teamsself.score = 0def score_basket(self):self.score += 2def print_score(self):print self.score
class Human(object):def __init__(self, name):self.name = namedef print_name(self): print self.nametom = Human("Tom")loraine = Human("Loraine")tom.age = 30print tom.age, loraine.age
class Human(object):expected_lifetime = 80def __init__(self, name):self.name = nametom = Human("Tom")loraine = Human("Loraine")print tom.expected_lifetime, loraine.expected_lifetime
"strings are objects with properties and methods"["lists are objects"]{"as_are": "dictionaries"}5 ### same with integers, floats, and Booleans -- they're more complicateddef even_a_func_is_an_object():print Trueeven_a_func_is_an_object.really = True
class Animal(object):def __init__(self, name):self.name = nameclass Fish(Animal): def __init__(self, name, habitat): super(Fish, self).__init__(name) self.habitat = habitatclass Salmon(Fish): def swim():print "upstream"class Halibut(Fish): def communicate():print "yarp" class GeneticHybridFish(Salmon, Halibut): passfish = GeneticHybridFish("Roy", "Brazil")