4.6. Standard Type Built-in Functions

Along with generic operators which we have just seen, Python also provides some built-in functions that can be applied to all the basic object types: cmp(), repr(), str(), type(), and the single reverse or back quotes ( '' ) operator, which is functionally-equivalent to repr().

Table 4.4. Standard Type Built-in Functions
functionoperation
cmp(obj1, obj2)compares obj1 and obj2, returns integer i where:

i < 0 if obj1 < obj2

i > 0 if obj1 > obj2

i == 0 if obj1 == obj2
repr(obj)/' obj'returns evaluatable string representation of obj
str(obj)returns printable string representation of obj
type(obj)determines type of obj and return type object

4.6.1. cmp()

The cmp() built-in function CoMPares two objects, say, obj1 ...

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.