Python type conversion, numeric manipulation

Source: Internet
Author: User
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])  Create a complex number str (x) to                 convert an object x to a string repr (x) to                convert an object x to an expression string eval (str)              to evaluate a valid Python expression in a string and return an object tuple (s) Converts a               sequence s to a tuple list (s) converts a                sequence s to a list Chr (x) converts                 an integer to a character unichr (x) converts              an integer to a Unicode character, Ord (x)                 Converts a character to its integer value hex (x) converts                 an integer to a hexadecimal string Oct (x)                 converts an integer to an octal string

The sequence supports the following:

Operation                      Description S + R                   sequence connection S * N, n * s           s n times copy, n is integer s% d                   string formatted (string only) S[i]                    index S[I:J]                slice x in S, X is in s< c6/> dependency for X in S:            iteration len (s)                  length min (s)                  min element max (s)                  max element S[i] = x               is s[i] re-assignment s[i:j] = R re-            assigns list fragment Value del s[i]               Delete an element from the list del s[i:j]            delete a fragment from the list

Numeric operation:

X << y                  left x >> y                  right shift x & Y bitwise                   and X | y bitwise                   or x ^ y bitwise                   XOR (exclusive OR) ~x bitwise                      Rollover x + y                   plus X- Y                   minus x * y                   multiply x                   /y general except X//y                  floor except × * * * y powers                  (xy) x y                   modulo (x mod y)-x                      change the symbol bit of the operand +x                      do nothing ~ X                      ~x=-(x+1) ABS (x)                 absolute value divmod (x, y)           return (int (x/y), x% y) pow (×, y [, modulo])    return (x * y) x% Modu Loround (x, [n])           rounded, n is the number of decimal places x < Y is                   less than x > y                   is greater than x = = y                  equals x! = y                  is not equal (same as <>) x >= y
  
    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.