python_number_operations

Python Number Operations

Operations

Number types support all number operations (see Table 6). In mixed-type expressions, Python converts operands up to the type of the “highest” type, where integer is lower than floating-point, which is lower than complex. As of Python 3.0 and 2.6, integer and floating-point objects also have a handful of type-specific methods and other attributes; see Python’s Library Reference manual for details:

(2.5).as_integer_ratio() # float attrs (5, 2) »> (2.5).is_integer() False »> (2).numerator, (2).denominator # int attrs (2, 1) »> (255).bit_length(), bin(255) # 3.1+ method (8, '0b11111111')
python_number_operations.txt · Last modified: 2024/04/28 03:21 by 127.0.0.1