本人正在学Python入门基础,用macos(12.0.1)在使用Python 3(IDLE Shell 3.10.0)使用isinstance函数判断类型,一直报错是什么原因?使用type函数的时候是没问题的。
a = 1
isinstance(a,str)
Traceback (most recent call last):
File "<pyshell#122>", line 1, in <module>
isinstance(a,str)
TypeError: 'tuple' object is not callable
isinstance(a,int)
Traceback (most recent call last):
File "<pyshell#123>", line 1, in <module>
isinstance(a,int)
TypeError: 'tuple' object is not callable
type(a)
<class 'int'>
a = 'hello'
isinstance(a,str)
Traceback (most recent call last):
File "<pyshell#126>", line 1, in <module>
isinstance(a,str)
TypeError: 'tuple' object is not callable
isinstance(a,int)
Traceback (most recent call last):
File "<pyshell#127>", line 1, in <module>
isinstance(a,int)
TypeError: 'tuple' object is not callable
type(a)
<class 'str'>
我已经检查过很多次,输入法,标点符号,空格都是对应的也是在英文输入法下输入的。
请各位指点!
谢谢
TypeError: 'tuple' object is not callable。这又是一个type error。
报错意思是tuple对象是不可调用的,
你好,根据你的问题,图报错现象来看
TypeError: 'tuple' object is not callable
这个错误应该是isinstance在使用以前被赋值为元组对象,模拟错误代码如下
isinstance=(1,2)
a=1
print(isinstance(a,str))
运行报错如下
Traceback (most recent call last):
File "F:\project\Question\main.py", line 4556, in <module>
print(isinstance(a,str))
TypeError: 'tuple' object is not callable
你检查一下文件中是否有isinstance被赋值的情况,
如果是python shell环境,建议你重启一下shell环境即可
有帮助请采纳,如未解决你的问题可以继续交流
isinstance("1",(str,))
第二参数用元组的方式传入