Python Learning Record (base-2)

Source: Internet
Author: User

Python built-in type

The main built-in types are numbers, sequences, mappings, classes, instances, and exceptions

Python Data Type Number

Integer integers: The operations performed are integers. Such as

>>>a = 10/3>>>a3

Long integers: Long integer is a superset of integral type. That is, a long integer can represent a larger number than an integral type. Python's long integer expression values are related to computer-supported (virtual) memory. For example

>>>a = 123456L

Float floating point Numbers: 8 bytes (64 bits) per floating-point type. Double-precision floating-point type. For large or very small floating-point numbers, it must be expressed in scientific notation, the 10 is replaced with E, 1.23x109 is 1.23e9 , or 12.3e8 , 0.000012 can be written as 1.2e-5 , and so on. Information about the precision of floating-point types and their internal characteristics in specific machines can be sys.float_info Obtained in .

>>> float ('+1.23')1.23>>> float ('   -12345\ n')-12345.0>>> float ('1e-003')0.001 >>> float ('+1E6')1000000.0>>> float (' -infinity ' )-inf

Complex Complex Numbers: A combination of a real number and an imaginary number forms a complex number. A complex number is a pair of ordered floating-point types (x, y), which is represented as the imaginary part of the Yj,yj. The imaginary numbers are now widely used in numerical and scientific computing applications.

A = 1 + 2j
#复数的内建属性
A.real #实部
A.imag #虚部
A.conjugate () #共轭根式
Print (A.real)
Print (A.IMAG)
Print (A.conjugate ())

Operation Result:

1.0
2.0
(1-2J)

Process finished with exit code 0

Data operations

All numeric types (except complex numbers) are normal operations, and here I write several operators that are unique to Python. (Note: All operations have a higher priority than the comparison operation):

Floor except//: The decimal part of the result is removed, returning the nearest number in a sequence of numbers that is smaller than the true quotient.

x = 5= 2>>>x//y  2

A =-1
b = 2
>>>a//b
-1

Power Operation * *: Its execution priority is lower than the unary operator of its left operand, which has a higher precedence than the unary operator of its right-hand operand.

>>>9 * * 281>>>-9 * * 2-81>>> ( -9) * * 2  # brackets Increase Execution Priority 81>>>4.0 * *- 1.00.25
Bit arithmetic

Bitwise operations are only applicable to integer, Standard bitwise operations: ~ Negation, & with, | or, ^ XOR. The inventor of Python is also a mathematician, so there are many mathematical operators and it is convenient to use them. There is also left shift << and right shift >>.

Binary bitwise operations have lower precedence than numeric operations and are higher than comparison operations; unary operations ~ have the same precedence as other unary operations ( + and - ).

This table lists the bitwise operations arranged in ascending order:

Operation Results
x | y Bitwise or of X and Y
x ^ y Bitwise XOR of X and Y
x &amp; y The bitwise and of X and Y
x n X left shift n bit
x >&gt; n X right shift n bit
~x Invert each bit of X

#举个小栗子, you can try it on your own.

>>> A = 65
>>> b =46
>>> A & B
0
>>> A = 1
>>> B = 1
>>> A & B
1

On the left shift operation of binary, some problems of the original code complement are involved. I want to understand a bit more thoroughly, so leave a white here, later fill in:)

Python Learning Record (base-2)

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.