class My:
def func(self) #类体
self.name = ‘xmb‘
pass
def func2(self):
self.func()
m = My()
m.func()
m.name
def buyCar(): print(‘买车‘) def baoxian(): print(‘保险‘) def jiaoshui(): print(‘交税‘) def shangpai(): print(‘上牌‘)
class BuyCar: def buyCar(): print(‘买车‘) def baoxian(): print(‘保险‘) def jiaoshui(): print(‘交税‘) def shangpai(): print(‘上牌‘)
xm = BuyCar() #类实例化
xm.baoxian()
1 class Person: 2 def __init__(self): 3 self.__base_price = 8000 #私有变量 4 print("构造函数")
1 class Person: 2 def __del__(self): 3 print("析构函数")
class Person: #经典类 #属性就是变量 #功能就是函数 country = ‘China‘ #类变量 base_price = 8000 discount = 0.1
class Person: #经典类 @staticmethod def help(): #静态方法 print("静态方法")
1 class Preson: 2 @classmethod #类方法 3 def sayCountry(cls): 4 #代表本身的这个类 5 print(cls.country)
原文:https://www.cnblogs.com/xumb/p/11963547.html