Python uses dictionary dict to determine whether a specified key value exists

Source: Internet
Author: User
Tags in python

This article mainly introduces Python to judge the existence of the specified key value through the dictionary Dict method, example analysis of Python using Has_key and in the judgement of the existence of the specified key value is very practical value, the need for friends can refer to the

This example describes how Python can determine whether a specified key value exists through a dictionary dict. Share to everyone for your reference. Specifically as follows:

There are two ways in Python to determine whether a specified key value exists, one that is has_key by the method of the Dictionary object, the other is through the in method, and the following is a detailed example.

?
1 2 3 4 5 d={' site ': ' http://www.jb51.net ', ' name ': ' jb51 ', ' is_good ': ' Yes '} #方法1: Through Has_key print d.has_key (' site ') #方法2: through in print ' body ' in D.keys ()

I hope this article will help you with your Python programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.