Search code examples
pythonrubydictionarysymbolslanguage-comparisons

Is there a Python equivalent to Ruby symbols?


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 keys in dictionaries only?


Solution

  • 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.