查看dict是否有密钥的方法 [英] Way for see if dict has a key

查看:86
本文介绍了查看dict是否有密钥的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

查看dict是否有钥匙的首选方法是什么?

我们有很多解决方案:

dict中的

dict.keys中的
键()

dict.has_key(键)

....


但更好或更多pythonic?


谢谢,

Michele

Hi ng,
what the preferred way for see if the dict has a key?
We have a lot of solutions:

key in dict
key in dict.keys()
dict.has_key(key)
....

but what the better or the more "pythonic"?

Thanks,
Michele

推荐答案

Michele Petrazzo写道:
Michele Petrazzo wrote:
查看dict是否有密钥的首选方法是什么?
我们有很多解决方案:

键入dict


新语法(2.3及更高版本)。

键dict.keys ()


低效无意义。

dict.has_key(key)


旧语法;用于需要向后兼容的代码。

但更好或更多pythonic?
what the preferred way for see if the dict has a key?
We have a lot of solutions:

key in dict
new syntax (2.3 and later).
key in dict.keys()
inefficient and pointless.
dict.has_key(key)
old syntax; use for code that needs to be backwards compatible.
but what the better or the more "pythonic"?




见上文。


< / F>



see above.

</F>


星期五,2006年6月30日10:19:46 +0000,Michele Petrazzo写道:
On Fri, 30 Jun 2006 10:19:46 +0000, Michele Petrazzo wrote:
你好,
看看dict是否有钥匙的首选方式是什么?
我们有很多解决方案:

键盘dict.keys()键盘dict.has_key(键)


但更好或更多pythonic?

谢谢,
Michele
Hi ng,
what the preferred way for see if the dict has a key?
We have a lot of solutions:

key in dict
key in dict.keys()
dict.has_key(key)
...

but what the better or the more "pythonic"?

Thanks,
Michele




这是一个宗教电话....



It is a religious call....


Fredrik Lundh写道:
Fredrik Lundh wrote:
Michele Petrazzo写道:
Michele Petrazzo wrote:
查看dict是否有密钥的首选方法?
我们有很多解决方案:

键入dict
what the preferred way for see if the dict has a key?
We have a lot of solutions:

key in dict



新语法(2.3及更高版本)。



new syntax (2.3 and later).




所以,跟着它,它可以用于像len这样的操作吗?

len(dict) - > len(dict.keys())?


谢谢,

Michele



So, following it, it can be used for the operations like len?

len(dict) -> len(dict.keys()) ?

Thanks,
Michele


这篇关于查看dict是否有密钥的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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