big-bozi

首先是学习@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()

 

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2021-07-15
  • 2022-12-23
  • 2021-10-14
  • 2021-08-13
  • 2021-04-13
  • 2021-11-17
  • 2021-06-08
猜你喜欢
  • 2021-05-19
  • 2021-05-28
  • 2021-10-15
  • 2021-07-09
  • 2021-11-17
  • 2021-10-11
  • 2021-04-03
相关资源
相似解决方案