Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways for python to query whether the key-value pair is in the dictionary?

Shulou Source: shulou.com Published: 2022-06-03 12:11:03 09月17日 Update

This article is to share with you about the method of querying whether the key-value pair of python is in the dictionary. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

We generally do key value query, will choose in or not in to operate, this article will also introduce three new query methods, let's take a look at it.

1. The keys () method is used to return all the key in the dictionary.

2. The values () method is used to return the value of all the keys in the dictionary.

3. Items () is used to return all key-value pairs (key-value) in the dictionary.

Example

Scores = {'Mathematics': 95, 'English': 92, 'Chinese': 84, 'Chemistry': 90, 'Biology': 91, 'Physics': 80} print ("judging whether a key-value pair is included in a dictionary") print ("whether mathematics is included in scores", "mathematics" in scores) print ("whether geography is included in scores", "geography" in scores) print ("whether history is included in scores" 'History 'not in scores) print (scores.keys ()) print (scores.values ()) print (scores.items ()) Thank you for reading! This is the end of this article on "python query key-value pairs are in the dictionary". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Dictionaries methods queries mathematics content history geography more see articles good practical chemistry examples articles physics biology knowledge Chinese English Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker NVidia OPPO Reno Linux