简体   繁体   English

isinstance(dataset, (list,)) 和 isinstance(dataset, list) 的区别

[英]Difference between isinstance(dataset, (list,)) and isinstance(dataset, list)

  1. isinstance(dataset, (list,))
  2. isinstance(dataset, list)

我知道 isinstance 用于查找特定变量是否属于该特定数据类型,但是您能否让我知道上面提到的 1 和 2 之间的确切区别

In this context, this is not much of a difference.在这种情况下,这没有太大区别。 The first one is used when you're trying to determine whether or not an object belongs to any of the datatypes are presented in the tuple.当您尝试确定对象是否属于元组中显示的任何数据类型时,将使用第一个。 Look at the example below:看下面的例子:

a = [3, 3, 2]
# a object is an instance of class list or str?
print(isinstance(a, (list, str)))
# it is equivalent with 
print(isinstance(a, list) or isinstance(a, str))

output:输出:

True
True

for more complement explanations refer to here !更多补充解释请参考这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM