'dict' object has no attribute 'has_key' solution

I recently started learning Python, installed the latest Python 3.3.3 and typed a small program according to the book, and the result was an error

‘dict’ object has no attribute 'has_key'

I couldn't find a solution on the Internet, but later I found out that the Python version was too new! The has_key() method was removed after Python 3!

Solution:

1. Reinstall Python, 2.7.6 is recommended, and more people use it. Many people are not used to using 3 and still use 2

2. Modify the code

if adict.has_key(key1):
change to

if key1 in adict:

Summary: if there is a problem, hit help() more often



Related: 'dict' object has no attribute 'has_key' solution