Python中如何实现自定义类的__call__方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计56个文字,预计阅读时间需要1分钟。
车型:Car,价格=10万
class Car:price = 100000 #定义类属性
def __init__(self, c):
self.color = c #定义实例属性
print("__init__")
def __call__(self):
print("__call__")
c = Car(4)
c() # __call__
本文共计56个文字,预计阅读时间需要1分钟。
车型:Car,价格=10万
class Car:price = 100000 #定义类属性
def __init__(self, c):
self.color = c #定义实例属性
print("__init__")
def __call__(self):
print("__call__")
c = Car(4)
c() # __call__

