SoFunction
Updated on 2024-11-19

Python's example of determining whether a dict contains a key value.

Looking it up, Python can determine whether a dictionary contains a key in two ways

1、(dict.has_key('keyname'))

2、('keyname' in dict)

I thought the second way was too ugly, so I wanted to use the first function, but pycharm kept reporting an error

Check the official information to get:

Python no longer supports the has_key() function, which has been replaced by __contains('keyname')

Above this Python judgment dict whether to contain a key value of the example to explain is all that I have shared with you, I hope to be able to give you a reference, and I hope that you support me more.