没找到需要的内容?换个关键词再搜索试试 向你推荐 为什么提示TypeError: 'int' object is not callable? 第二种方法出现错误'module' object is not callable tuple object has no attribute items TypeError: 'NoneType' object is not iterable
4 如何调用tuple里的一个原始呢?和list中一样,用a[0] 而不是a(0),圆括号是调用函数的方法。>>> a=(1,2,3)>>> a(1, 2, 3)>>> a(0)Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> a(0)TypeError: 'tuple' object is not callable>>...
由于命名元组继承自元组,我们仍然可以像处理其他元组一样处理它们:通过索引、切片、迭代。 Coords = namedtuple('Coords', ['x', 'y']) coord=Coords(10,20) isinstance(coord,tuple) --> True # namedtuple is subclass of tuple x,y=coord # Unpacking x=coord[0] # by index for e in coord: print...