Called to implement the built-in function len(). Should return the length of the object, an integer >= 0. Also, an object that doesn’t
define a __nonzero__() method and whose __len__() method returns zero
is considered to be false in a Boolean context.
__len__
应返回int
>;=0。参见docs错误就是这么说的。在
您返回的是一个字符串(
'[]'
),它不是int
,因此引发了此错误。返回0将更合适。在
^{cd1>}的返回值必须是^{{cd2>}。因此,当列表为空时返回0。
从docs开始:
相关问题 更多 >
编程相关推荐