Numeric Type Operators and Functions


Table B.3 represents the operators and (built-in and factory) functions that apply to Python's numeric objects.

Table B.3. Operators and Built-in Functions for All Numeric Types

Operator/built-in

Description

int

long

float

complex

Result[a]

abs()

Absolute value

number[a]

chr()

Character

  

str

coerce()

Numeric coercion

tuple

complex()

Complex factory function

complex

divmod()

Division/modulo

tuple

float()

Float factory function

float

hex()

Hexadecimal string

  

str

int()

Int factory function

int

long()

Long factory function

long

oct()

Octal string

  

str

ord()

Ordinal

(string)

int

pow()

Exponentiation

number

round()

Float rounding

  

 

float

**[b]

Exponentiation

number

+[c]

No change

number

-[c]

Negation

number

~[c]

Bit inversion

  

int/long

**[b]

Exponentiation

number

*

Multiplication

number

/

Classic or true division

number

//

Floor division

number

%

Modulo/remainder

number

+

Addition

number

-

Subtraction

number

<<

Bit left shift

  

int/long

>>

Bit right shift

  

int/long

&

Bitwise AND

  

int/long

^

Bitwise XOR

  

int/long

|

Bitwise OR

  

int/long


[a] A result of "number" indicates any of the numeric types, perhaps the same as the operands.

[b] ** has a unique relationship with unary operators; see Section 5.5.3 and Table 5.2.

[c] Unary operator.



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net