美文网首页
类与实例

类与实例

作者: aiyolo | 来源:发表于2017-06-07 19:24 被阅读4次
    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]
    
    
    

    相关文章

      网友评论

          本文标题:类与实例

          本文链接:https://www.haomeiwen.com/subject/ymuctxtx.html