我这里使用 Win7 Python3.8.6,
如果
class Student(object):
def __init__(self, name):
self.name = name
def __call__(self):
print('My name is %s.' % self.name)
然后
callable(Student())
显示 TypeError:__init__() missing 1 required positional argument : 'name'
如果改成
def __init__(self, name='a'):
显示 True
Sign in to make a reply
VincyChan4231
我这里使用 Win7 Python3.8.6,
如果
class Student(object):
def __init__(self, name):
self.name = name
def __call__(self):
print('My name is %s.' % self.name)
然后
callable(Student())
显示 TypeError:__init__() missing 1 required positional argument : 'name'
如果改成
class Student(object):
def __init__(self, name='a'):
self.name = name
def __call__(self):
print('My name is %s.' % self.name)
然后
callable(Student())
显示 True