Skip to content

Files

Latest commit

 

History

History
27 lines (18 loc) · 499 Bytes

File metadata and controls

27 lines (18 loc) · 499 Bytes

Pattern: Use of deprecated .has_key()

Issue: -

Description

.has_key() was deprecated in Python 2. It is recommended to use the in operator instead.

Example of incorrect code:

my_dict = {'hello': 'world'}
if my_dict.has_key('hello'):
    print('It works!')

Example of correct code:

my_dict = {'hello': 'world'}
if 'hello' in my_dict:
    print('It works!')

Further Reading