classmethod练习

# class Cou:
# __discount=0.8
# def __init__(self):
# self.price=5
# self.price=self.price*self.__discount
# @property
# def nowdiscount(self):
# print(Cou.__discount)
# @nowdiscount.setter
# def nowdiscount(self,newdiscount):
# Cou.__discount=newdiscount
# appele=Cou()
# print(appele.price)
# appele.nowdiscount
# appele.nowdiscount=0.5
# appele=Cou()
# appele.nowdiscount
# print(appele.price)




# class A:
# __discount=0.8
# def __init__(self,price):
# self.price=A.__discount*price
# def changweight(self,newdiscount):
# A.__discount=newdiscount
# a=A(10)
# print(a.price)
# a.changweight(0.6)
# a=A(10)
# print(a.price)

# #classmethod
# class A:
# __discount=0.8
# def __init__(self,price):
# self.price=A.__discount*price
# @classmethod
# def changediscount(cls,newdiscount):
# cls.__discount=newdiscount
# a=A(10)
# print(a.price)
# a.changediscount(0.6)
# # A.changediscount(0.6)
# a=A(10)
# print(a.price)
# import time
# class Date:
# def __init__(self,year,month,day):
# self.year = year
# self.month = month
# self.day = day
# @classmethod
# def today(cls):
# date=cls(time.localtime().tm_year,time.localtime().tm_mon,time.localtime().tm_mday)
# return date
# print(Date.today().year)
# print(Date.today().month)
# print(Date.today().day)
原文地址:https://www.cnblogs.com/diracy/p/13473211.html