Linux 拨号vps windows公众号手机端

map如何判断是否有某一个key

lewis 7年前 (2018-04-05) 阅读数 11 #程序编程
文章标签 MAP

在python中,可以使用in关键字来判断一个key是否存在于map中。示例代码如下:

my_map = {'a': 1, 'b': 2, 'c': 3}

if 'a' in my_map:
    print('Key "a" exists in the map.')
else:
    print('Key "a" does not exist in the map.')

以上代码将输出Key "a" exists in the map.,因为map中存在key为'a'的键。如果要判断一个key是否不存在于map中,可以使用not in关键字。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门