zoukankan      html  css  js  c++  java
  • 廖雪峰老师的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()
  • 相关阅读:
    hlgoj 1766 Cubing
    Reverse Linked List
    String to Integer
    Bitwise AND of Numbers Range
    Best Time to Buy and Sell Stock III
    First Missing Positive
    Permutation Sequence
    Next Permutation
    Gray Code
    Number of Islands
  • 原文地址:https://www.cnblogs.com/big-bozi/p/6953927.html
Copyright © 2011-2022 走看看