有没有Python相当于Ruby符号? [英] Is there a Python equivalent to Ruby symbols?

查看:141
本文介绍了有没有Python相当于Ruby符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有与Ruby符号相当的Python?




  • 如果是,那么是什么?


  • 如果没有,那么我们是否只在字典中使用字符串作为我们的



解决方案

不,python没有符号类型。



但是,默认情况下,和其他字符串可以使用 intern 函数进行实习。所以在字典中使用字符串文字作为键,与使用ruby中的符号相比,性能并不逊色。


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?

解决方案

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.

这篇关于有没有Python相当于Ruby符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆