+ -
当前位置:首页 → 问答吧 → __init__中无法return?

__init__中无法return?

时间:2011-06-17

来源:互联网

>>> class a(object):
...  def __init__(self, xx):
...   self.xx = xx
...   return 'the xx value is %s'%self.xx

>>>a('test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() should return None, not 'str'

作者: firmlyjin   发布时间: 2011-06-17

__init__只是一个构造(初始化)函数,为什么要return?

作者: leetschau   发布时间: 2011-06-17