【问题标题】:Difference between these Python structures这些 Python 结构之间的区别
【发布时间】:2014-01-29 07:00:14
【问题描述】:

两者有什么区别:

things = []

things = {}

things = set()

我尝试用谷歌搜索,但很难用谷歌搜索像这样的结构,只有括号来识别它们而不知道它们的实际名称。

我还看到 (element1, element2) 作为参数传递给函数,但我不知道 Python 将其解释为什么。

【问题讨论】:

  • 它们被称为listdictset到谷歌手机!
  • 在这些事物上尝试type函数。
  • 你在哪里找到这些符号,肯定会解释它们是什么,你可能不需要在这里问。

标签: python arrays list set


【解决方案1】:

这些是

  1. list
  2. dict
  3. set

欢迎使用 Python!

哦,我忘了说,如果您也是 Python 新手(甚至不是),我建议您查看 IPython

当你对 python 一无所知时,只需这样做:

help(thing)

例如

help([]) # will show this ...
Help on list object:

class list(object)
 |  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable's items
 |  

【讨论】:

    【解决方案2】:

    在 C++ 世界中,它们是

    • list [] = std::vector
    • set = std::set
    • dict {} = std::map

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2012-09-02
      • 2021-02-09
      • 1970-01-01
      相关资源
      最近更新 更多