Python type conversion function description python type conversion
Function description
Int (x [, base]) converts x to an integer.
Long (x [, base]) converts x to a long integer.
Float (x) converts x to a floating point number.
Complex (real [, imag]) creates a plural number
Str (x) converts object x to a string
Repr (x) converts object x to an expression string
Eval (str) is used to calculate a valid Python expression in a string and return an object.
Tuple (s) converts the sequence s into a tuples
List (s) converts sequence s into a list
Chr (x) converts an integer to a character
Unichr (x) converts an integer to a Unicode character
Ord (x) converts a character into its integer
Hex (x) converts an integer into a hexadecimal string.
Oct (x) converts an integer into an octal string
The sequence supports the following operations:
Operation description
S + r sequential join
S * n, n * s n copies, n is an integer
S % d string formatting (string only)
S [I] Index
S [I: j] slice
X in s, x not in s subordination
For x in s: Iteration
Len (s) length
Min (s) minimum element
Max (s) maximum element
S [I] = x is s [I] re-assigned
S [I: j] = r: returns the list fragment value.
Del s [I] deletes an element from the list.
Del s [I: j] deletes a clip from the list.
Numeric operation:
X <y shifts left
X> y shift right
X & y
X | y by bit or
X ^ y exclusive or)
~ X flip by bit
X + y Plus
X-y subtraction
X * y multiplication
X/y
X // y floor Division
X ** y multiplication (xy)
X % y modulo (x mod y)
-X changes the symbol bit of the operand.
+ X does nothing.
~ X ~ X =-(x + 1)
Abs (x) absolute value
Pmod (x, y) returns (int (x/y), x % y)
Pow (x, y [, modulo]) returns (x ** y) x % modulo
Round (x, [n]) rounding, n is the number of decimal places
X <y is less
X> y is greater
X = y equals
X! = Y is not equal to (same as <>)
X> = y is greater than or equal
X <= y is less than or equal