Free cookie consent management tool by TermsFeed Python Dictionary - not in function | Pythontic.com

Python Dictionary - not in function

key not in dict

Method Overview:

  • The operator not in checks whether a given key is not present in a Python dictionary. If the key is not present returns TRUE else returns FALSE.
  • The not in operator behaves the opposite of the in operator.

Example:       

# Example Python progran that checks whether
# a given key is present in a dictionary

environmentDictionary = {'path': '/bin:/opt/bin'}

if 'path' not in environmentDictionary:       
     print('Path is not set')
else:
     print('Path is set')

Output:

Path is set

 


Copyright 2025 © pythontic.com