7.2. Operators

Dictionaries do not support sequence operations such as concatenation and repetition, although an update() built-in method exists that populates one dictionary with the contents of another. Dictionaries do not have a “membership” operator either, but the has_key() built-in method basically performs the same task.

7.2.1. Standard Type Operators

Dictionaries will work with all of the standard type operators. These were introduced in Chapter 4, but we will present some examples of how to use them with dictionaries here:

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

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.