Python type conversion, sequence, numeric operations

Source: Internet
Author: User
Python type conversion:
Code:
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

Supported sequence operations:
Code:

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:
Code:

Python code
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
Divmod (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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.