Is there a Python equivalent to Ruby symbols?

后端 未结 5 1171
时光说笑
时光说笑 2020-12-13 23:39

Is there a Python equivalent to Ruby symbols?

  • If so then what is it?

  • If not then are we stuck with using strings as our

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 00:10

    No, python doesn't have a symbol type.

    However string literals are interned by default and other strings can be interned using the intern function. So using string literals as keys in dictionaries is not less performant than using symbols in ruby.

提交回复
热议问题