PHP
·
发表于 5年以前
·
阅读量:8296
>>> callable(str)
True
>>> callable(int)
True
# Student 对象实例目前不可调用:
>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student(id='1',name='xiaoming')
>>> callable(xiaoming)
False
# 如果 xiaoming能被调用 , 需要重写Student类的__call__方法:
>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
# 此时调用 xiaoming():
>>> xiaoming = Student('001','xiaoming')
>>> xiaoming()
I can be called
my name is xiaoming