A detailed description of the type conversion method in Python

Source: Internet
Author: User
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 complex number

STR (x) converts an object x to a string

REPR (x) converts an object x to an expression string

Eval (str) is used to calculate a valid Python expression in a string and returns an object

Tuple (s) converts a sequence s to a tuple

List (s) converts the sequence s to a list

Chr (x) converts an integer to one 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 formatting (string only)

S[i] Index

S[I:J] Slices

X in S, X isn't in S dependency

For x in S: Iteration

Len (s) length

Min (s) min element

Max (s) max element

S[i] = x is s[i] re-assigned

S[I:J] = R re-assigns the list fragment

Del S[i] Remove an element from the list

Del S[i:j] Delete a fragment from the list

Operation description

S + R sequence connection

S * N, n * s S n times copy, n is integer

S% d string formatting (string only)

S[i] Index

S[I:J] Slices

X in S, X isn't in S dependency

For x in S: Iteration

Len (s) length

Min (s) min element

Max (s) max element

S[i] = x is s[i] re-assigned

S[I:J] = R re-assigns the list fragment

Del S[i] Remove an element from the list

Del S[i:j] Delete a fragment from the list

Numeric operation:

x << y shift left

x >> y Shift Right

X & y Bitwise AND

x | Y bitwise OR

x ^ y bitwise XOR (exclusive OR)

~x rollover by bit

x + y Plus

X-y minus

X * y Multiply

X/y general except

X//Y floor except

X * * y-exponentiation (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 (x, y [, modulo]) returns (x * * y) x% modulo

Round (x, [n]) rounded, n is the number of decimal places

x < y less than

x > Y greater than

x = = y equals

X! = y Not equal (same as <>)

x >= y is greater than or equal to

X <= y is less than or equal to

Related Article

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.