Describes the concepts and usage of ing type (dictionary) Operators in Python, and python operators.

Source: Internet
Author: User
Tags element groups

Describes the concepts and usage of ing type (dictionary) Operators in Python, and python operators.

Ing Type Operator

(1) standard operators

The dictionary can work with all standard type operators, but it does not support operations such as concatenation and repetition. These operations are meaningful to the sequence and do not work for the ing type.
How are dictionaries compared? Like lists and element groups, this process is more complex than numbers and strings.
(2) ing type operators
Dictionary key search operator ([])
The key search operator is a unique dictionary-type operator. It is very similar to the slice operator of a single element in the sequence type. For sequence types, use an index as a unique parameter or subscript to obtain the value of an element in a sequence. For the dictionary type, keys are used to query the elements in the dictionary. Therefore, keys are parameters rather than indexes ). The key search operator can be used to assign values to the dictionary or to take values from the dictionary.
(Key) member relationship operation (in, not in)
From Python 2.2, you can use the in and not in operators to check whether a key exists in the dictionary instead of the has_key () method.


Simple Example:

Standard Operators

>>> dict4 = {'abc': 123}>>> dict5 = {'abc': 456}>>> dict6 = {'abc':123,98.6:37}>>> dict7 = {'xyz':123}>>> dict4 < dict5True>>> (dict4 < dict6) and (dict4 < dict7)True>>> (dict4 < dict6) and (dict5 < dict7)True>>> dict6 < dict7False


Dictionary key-over-search operator ([])

>>> 'name' in dict2True>>> 'phone' in dict2False

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.