How to check whether a key already exists in a dict in Python since version 2.6? If d is a dict(), you can directly test whether a key k is in d in Python by the in keyword likeif k in d: .. Related posts:How to get the value of a default value if the key does not exist in `dict()` in Python? How to test whether a file exists and is a block special file in Python on Linux? How to test whether a user already exist on Linux? How to check whether a file of a given path is a block device in Python? How to test a file or directory exists in Python? How to check whether a function has been defined in Bash? How to detect whether a file is readable and writable in Python? How to check whether a string starts with another string in C++?