本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

与使用“is”的关键字“list”和“set”相比,为什么空列表和 set 上的 type() 会产生不同的答案?[复制]

发布于2023-02-27 04:43     阅读(1188)     评论(0)     点赞(10)     收藏(2)


I am currently learning Python and was answering questions on a practice quiz where I encountered the following questions:

  1. What is the output of print(type({}) is set) ?
  2. What is the output of print(type([]) is list) ?

I am unsure on how to approach the justification as to why Q1. yields False, yet Q2. yields True. I am following the guidance from a relevant post detailing the nuances of the keyword is, yet I fail to see where the two differ when comparing lists vs sets.


解决方案


这不是关于is.

{}在 Python 中是一个空字典。在 Python 中没有用于创建空集的文字(请参阅此答案实际文档)。如果你要尝试type(set()) is set,你会生产True



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/493586/8627b114e90bb954500d/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

10 0
收藏该文
已收藏

评论内容:(最多支持255个字符)