Check element exists in array

后端 未结 6 818
说谎
说谎 2021-01-30 08:23

In PHP there a function called isset() to check if something (like an array index) exists and has a value. How about Python?

I need to use this on arrays because I get \

6条回答
  •  情歌与酒
    2021-01-30 09:04

    has_key is fast and efficient.

    Instead of array use an hash:

    valueTo1={"a","b","c"}
    
    if valueTo1.has_key("a"):
            print "Found key in dictionary"
    

提交回复
热议问题