zoukankan      html  css  js  c++  java
  • python练习题-day26

    #bim(property)
    class People:
        def __init__(self,name,weight,height):
            self.name=name
            self.weight=weight
            self.height=height
        @property
        def bim(self):
            return self.weight/(self.height**2)
    #property setter deleter
    class Foo:
        def __init__(self,val):
            self.__NAME=val
        @property
        def name(self):
            return self.__NAME
        @name.setter
        def name(self,value):
            self.__NAME=value
        @name.deleter
        def name(self):
            del self.__NAME
    #classmethod
    class Goods:
        __discount=0.8
        def __init__(self,name,price):
            self.name = name
            self.__price = price
        @property
        def price(self):
            return self.__price * Goods.__discount
        @classmethod
        def change_discount(cls,new_discount):
            Goods.__discount=new_discount
    apple=Goods("apple",10)
    print(apple.price)
    Goods.change_discount(0.9)
    print(apple.price)
    #反射
    class Teacher:
        dic={"查看学生信息":"","查看老师信息":""}
        def __init__(self):pass
        @classmethod
        def class_method(cls):
            print("test")
    if hasattr(Teacher,"class_method"):
        getattr(Teacher,"class_method")()
    
    print(getattr(Teacher,"dic"))
  • 相关阅读:
    Socket通信
    浏览器调用打印机
    python dict操作
    python list操作
    python 模块Example链接
    python random模块
    python configparser模块
    python unittest模块
    python timeit模块
    python datetime模块
  • 原文地址:https://www.cnblogs.com/fumy/p/10763760.html
Copyright © 2011-2022 走看看