5.6. Built-in Functions
5.6.1. Standard Type Functions
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'>
5.6.2. Numeric Type Functions
Python currently supports different sets of built-in functions for numeric types. Some convert from one numeric type to another while others ...
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.