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