1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
class Car: pass
class Car(): pass
class Car(object): pass
obj = Car() print(obj)
class Car(): color = "白色" def fun(self): print("燃油车")
class MyCar(): logo = "奥迪" __price = "2000万" def fun(self): print("百公里油耗7l") def __info(self): print("我的车")
obj = MyCar()
print(obj.logo) obj.fun()
obj.logo = "捷豹" obj.color = "黑色"
print(obj.__dict__) print(MyCar.__dict__)
def dhf(): print("我叫大黄蜂")
def qtz(name): print("我叫{}".format(name)) obj.qtz = qtz obj.qtz("擎天柱")
def qtz1(obj,name): print("我叫{},我的颜色是{}".format(name,obj.color)) obj.qtz1 = qtz1 obj.qtz1(obj,"擎天柱")
def qtz2(obj,name): print("我叫{},我的颜色是{}".format(name, obj.color))
import types
res = types.MethodType(qtz2,obj) print(res) obj.qtz2 =types.MethodType(qtz2,obj) obj.qtz2("擎天柱")
obj.wzt = lambda :print("我是威震天") obj.wzt()
|