December 2000
Intermediate to advanced
816 pages
16h 57m
English
In the last chapter, we introduced the cmp(), str(), and type() built-in functions that apply for all standard types. For numbers, these functions will compare two numbers, convert numbers into strings, and tell you a number's type, respectively. Here are some examples of using these functions:
>>> cmp(-6, 2)] -1 >>> cmp(-4.333333, -2.718281828) -1 >>> cmp(0xFF, 255) 0 >>> str(0xFF) '255' >>> str(55.3e2) '5530.0' >>> type(0xFF) <type 'int'> >>> type(98765432109876543210L) <type 'long int'> >>> type(2-1j) <type 'complex'>
Python currently supports different sets of built-in functions for numeric types. Some convert from one numeric type to another while others ...
Read now
Unlock full access