类与实例

class Student(object):
    def __init__(self, name, age, score):
        self.name = name
        self.score = score
        self.age = age
    def print_score(self):
        print 'name:%s\nage:%s\nscore:%s'%self.name, %self.age, %self.score


In [55]: bart = Student("barty", 21, 100)

In [56]: bart.__dict__
Out[56]: {'age': 21, 'name': 'barty', 'score': 100}

In [73]: bart = Student("barty", 21, 100)

In [74]: bart.print_score()
name:barty
age:21
score:100

In [116]: [x**y for x in range(3)for y in range(4)]
Out[116]: [1, 0, 0, 0, 1, 1, 1, 1, 1, 2, 4, 8]
In [120]: map(lambda x:x+3,range(2, 9))
Out[120]: [5, 6, 7, 8, 9, 10, 11]


你可能感兴趣的:(类与实例)