Python type conversion and numeric operations

Source: Internet
Author: User
Python type conversion function description int (x [, base]) converts x to an integer long (x [, base]) and converts x to a long integer float (x) convert x to a floating point complex (real [, imag]) to create a plural str (x )...
Function description int (x [, base]) converts x to an integer long (x [, base]) and converts x to a long integer float (x) convert x to a floating point complex (real [, imag]) to create a plural str (x). Convert x to a string repr (x) convert object x to expression string eval (str) to calculate a valid Python expression in the string, and return an object tuple (s) to convert the sequence s to a list (s) converts the sequence s to a list chr (x) and an integer to a character unichr (x). converts an integer to a Unicode character ord (x) convert a character to its integer hex (x) and convert an integer to a hexadecimal string oct (x). convert an integer to an octal string.

The sequence supports the following operations:

Operation description: the s + r sequence is connected to n copies of s * n, n * s, and n is an integer s % d. The string is formatted (only a string) 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) the smallest element max (s) the largest element s [I] = x is s [I] re-assigned s [I: j] = r: assign the list fragment value del s [I] again to delete an Element del s [I: j] in the list and delete a fragment in the list.

Numeric operation:

X <y shifts left x> y shifts right x & y by bit and x | y by bit or x ^ y by bit or (exclusive or )~ X flip x + y plus x-y minus x * y multiply x/y conventional division 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 % moduloround (x, [n]) rounded, n is the number of decimal places x <y is less than x> y is greater than x = y is equal to x! = Y is not equal to (and) x> = y is greater than or equal to 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.