廖雪峰老师的python教程中的几个学习笔记的备份

首先是学习@property的笔记

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/5/14 22:18
# @Author  : 15407_000
# @Site    : 
# @File    : 使用@property.py
# @Software: PyCharm

class student(object):
    score=10
    def getscore(self):
        return self.score

    def setscore(self,value):
        if not isinstance(value,int):
            raise ValueError("score must be int")
        if value <0 or value>100:
            raise ValueError("score must be 0~100")
        self.score=value
        pass
    pass

s=student()
s.setscore(60)
print(s.getscore())
s.setscore(1111)

然后是学习多重继承的:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/6/6 21:50
# @Author  : 15407_000
# @Site    : 
# @File    : 多重继承.py
# @Software: PyCharm

class A(object):
    def Run(self):
        print("A runs")
class B(object):
    def Run(self):
        print("B runs")
class C(B,A):#这里C类继承了A,也继承了B,但是调用的是B类的run方法。
    '''
    #但是如果是这样继承的:
    class c(A,B):
        pass
    那么调用run的时候会用A的run方法,而不是B的
    '''
    pass
x=C()
x.Run()

 

posted @ 2017-06-06 22:08  大博子  阅读(365)  评论(0编辑  收藏  举报