Integer type, float type, a plurality of types of basic data types

This article from students Mu class website Beijing Institute of Technology National Excellent Courses "python programming language," a class lecture notes, course addresses https://www.icourse163.org/learn/BIT-268001#/learn/announce

Type Integer: consistent with the concept of integer mathematics, the whole can be negative, no range limitations.
--Pow (x, y) function: y count x to the power of
an integer of the python provides four represents:
- Decimal: 1010,99, -217
- binary, or beginning 0B 0B: 0b101, -0B101
- - octal, beginning with 0o or 0O: 0o123, -0O456
- hexadecimal, begins with 0x or 0X: 0x9a, -0X89
floating-point type: real consistent with the concept of mathematics
- numbers with decimal points and decimals
- decimal precision floating-point range and has a limit, but conventional computing negligible
- an order of magnitude in the range from -10 308 to 10 308, the accuracy of the order of 10 ^ -16
Note: Room mantissa floating-point arithmetic uncertain, not a bug.
E.g:

0.1+0.2
0.30000000000000004

0.1+0.2==0.3
False

In such cases, it is possible to use round (x, d): for rounding x, d is taken decimal digits.

round(0.1+0.2,1)==0.3
Ture

Due to uncertainty of bits generally occurs in about 10 ^ -16, so the comparison between the floating-point operations and round () function is very effective aid.
Floating point made using scientific notation represented by
- e letters or symbols E as power, as the base 10, the following format:
e represents * 10 ^ B A
- For example: 4.3e-3 value is 0.0043 9.6E5 960000

Plural types: in many programming languages, there is only python type complex, which is consistent with a complex mathematical concepts.
, use z.real () acquires the real part of the complex, z.imag () the imaginary part of the complex obtained.
Types numeric operators
x + = y i.e. x = x + y x- = y i.e. x = xy x * = y i.e. x = x * yx / = y i.e. x = x / yx // = y i.e. x = x / / yx% = y% X i.e. Y = X
X = Y ** i.e. x = x ** y

Note: There are three types of one kind of data is gradually "extended" or "broadened" relationship:
a plurality> float> an integer of
different data types can be mixed operation, to generate the result "widest" Type
example: 123 = 127.0 + 4.0 (integer + = float float)
Python provides some built-in calculation function
abs (x), taking the absolute value of x
divmod (x, y), i.e., (x // y, x% y ), and simultaneously outputs the quotient I, e.g. dibmod (10,3) result (3,1)
POW (X, Y [, z]), i.e., (x ** y)% z, [...] represents the parameter z can be omitted, e.g. pow (3 , 3,5) is the result of 2
round (X [, D]), D is the number of decimal places to retain, the default value is 0, for example, round (-10.123,2) results -10.12
max (a, B, ...... , c) output the maximum value, min () output the minimum value
int (x) of x into an integer, a float (x) becomes the floating point x, complex (x) of x becomes complex, increasing the imaginary part.

Released six original articles · won praise 0 · Views 138

Guess you like

Origin blog.csdn.net/qq_43636375/article/details/104058482