7.3. Built-in Functions
7.3.1. Standard Type Functions [type(), str(), and cmp()]
The type() built-in function, when operated on a dictionary, reveals an object of the dictionary type. The str() built-in function will produce a printable string representation of a dictionary. These are fairly straightfoward.
In each of the last three chapters, we showed how the cmp() built-in function worked with numbers, strings, lists, and tuples. So how about dictionaries? Comparisons of dictionaries are based on an algorithm which starts with sizes first, then keys, and finally values. In our example below, we create two dictionaries and compare them, then slowly modify the dictionaries to show how these changes affect their comparisons:
>>> dict1 = {} ...
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.