[英]Error when using isinstance(sample_list,list) in python 3.x
When I run isinstance(names,list)
where names is a list, instead of getting True as the result, I get the following error message: 当我运行
isinstance(names,list)
,names是一个列表,而不是得到True作为结果,我收到以下错误消息:
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
isinstance(names,list)
TypeError: isinstance() arg 2 must be a type or tuple of types
I am using IDLE and Python 3.x 我正在使用IDLE和Python 3.x
Could anybody please point out what the problem is. 任何人都可以指出问题所在。
Because you probably created a variable named list
somewhere above in your code. 因为您可能在代码上方的某个位置创建了一个名为
list
的变量。
list = [1, 2, 3]
...
names = ['Joe', 'Jack', 'Jane']
...
if isinstance(names, list):
...
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
Never use type names such as set
, list
, file
, dict
etc. as a variable name in your code. 切勿在代码中使用
set
, list
, file
, dict
等类型名称作为变量名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.