This is the 15th day of my participation in Gwen Challenge

I will honour myself by showing up powerfully in my life today. I will be proud of myself for trying to live my life today.

Before we explained about the use of Python to write temperature converter, draw “Python” code, forget to click on the album to review oh, can also click on the code, improve the proficiency of the statement.

I haven’t written about Python for a few days, so I’ll cover Python as soon as possible, and then we can start to use Python in real life, such as crawlers, data analysis, etc.

Small make up today to type the number in the basic data types on the Python, for everybody about digital type, you may feel that simple, that’s right, is relatively simple, but still have to master some basic grammar knowledge, small make up preparation is divided into three parts, respectively, are three basic types (integer types and floating-point types, complex types). Numeric operators and numeric operation functions.

Because this part of the knowledge is not difficult, is not much, so xiaobian will try to explain in detail for you.

One. Three basic types

1. First of all, we are going to learn about integer types. This doesn’t sound too hard, after all, we have been exposed to integers since primary school. Of course not, their concept is the same, can be positive or negative, no limit on the range of values, xiaobian feel better than C language, after all, there is no limit on the size of the value.

In integer types, we will learn statements like:

The pow(x,y) #pow statement stands for x to the y power, e.g. Pow (2,100) means 2 to the 100 powerCopy the code

Another thing to note in the integer type is that we talked about base conversion and representation in C.

Portal: Multi-base conversion, have you learned?

Here xiaobian to supplement about the representation of the base:

2. Next we will learn floating point type, floating point concept and mathematics in the real number type, we also learned in C language, namely: with decimal point and decimal number, floating point value range and precision have certain restrictions, in general calculation can be ignored.

In Python, 0.1+0.1 = 0.2 is not true (even in C), which is incorrect. This is the accuracy limitation mentioned above, that is, there may be uncertain mantissa (non-zero) after 0.2. This has to do with the internal base conversion of the computer, which I won’t describe in detail here.

For example, xiaobian uses the following examples to demonstrate (if you are interested, you can also try oh):

If (0.1+0.2==0.3): print(" correct ") else: print(" wrong ")Copy the code

The output is bound to be wrong, so if we’re on a large project where this kind of math problem definitely needs the right answer, how do we get it right?

Here we need to use the round function. For example, let’s change the above code as follows:

If (round (0.1 + 0.2, 1) = = 0.3) : print (" right ") else: print (" error ")Copy the code

So the output is correct, so how does the round function work?

Round (x,d); round(x,d); round(x,d); If you’re not sure which mantissa comes first? No, the mantissa of uncertainty usually happens around 10 to the -16, so don’t worry about it.

Finally, there is a scientific notation for floating point numbers, which is also very simple and rarely used.

Scientific notation uses the letter e or e as a symbol for powers, with base 10.

The format is <a> E <b>, indicating a x 10 to the power B.Copy the code

For example, the value of 4.3E-3 is 0.0043. The value of 9.6E5 is 960000.0

3. Finally, there is the complex type, which is unique to Python. There is no such thing as a complex type in any other programming language. We learned about complex numbers in high school, so of course it’s the same thing as high school.

Well, someone originally said x squared if I have negative 1, what is the value of x? I have to say this guy’s amazing. He’s got a lot of imagination.

In complex numbers: A + BJ is called the complex number, where a is the real part, also called the real part; Bj is the imaginary part, b is the imaginary part.

For example,z =1.23e-4+5.6e+89j. in this expression, 1.23e-4 is the real part, and the following part is the imaginary part because of j. In the program, we can obtain the real part by using z.real and the imaginary part by using z.imag.

two Numeric operator

Much of the content of the numeric operators is the same as in C. For example, add, subtract, multiply, and divide, but Python has a //, which means to divide an integer, as well as a few others, listed below.

The unary operators are as follows:

X /y #x and y are the simplest integers divided by x//y #x. The integer quotient of x and y, such as 10//3, is 3 +x #x itself The remainder of -x #y is the negative value of x%y #, and the modular operation such as 10%. The result of 3 is 1 x**y #, and the operation of x to the y #. When y is a decimal, the root operation such as 10**0.5 results in the square root of 10.Copy the code

Secondly, there are binary operators in numerical operations, which we have learned in C language, this hand does not master the problem is not big, because the binary operator is the unary operator in the short form of operation, will be unary operator.

To: In Python numerical operations, it is important To note that when multiple types are used, the widest type (progressively wider) is generated: integer -> floating point -> complex

3. Numerical operation function

Since the last part contains functions, there will certainly be a lot of functions introduced, which is what we need to remember, the most important thing is to be able to use, even if not completely remember, must also know the use of this function, which will improve the efficiency of writing programs.

Here xiaobian will write his notes to show, about the use of these functions and points to pay attention to xiaobian in the example will be explained to you later, these statements are best in the program to knock again oh, try more, easy to remember.

Divmod (x//y,x%y): remainder, at the same time output quotient and remainder, such as: divmod(10,3) result is (3,1). Pow (x,y,[z]): remainder: (x **y) %z,[..] Indicates that parameter z can be omitted. For example,pow(3, pow(3,99),10000) is 4587 (the last four positions of 3 to the power of 99) min(x1,x2,x3... Xn): minimizes, returns x1,x2... The minimum value in Xn, n is unlimited. Min (1,9,5,3,4) = 1. Max (x1,x2,x3... Xn): maximum value, return x1,x2... The maximum value in Xn, n is unlimited. Max (1,9,5,3,4) = 9. Int (x): change x to an integer, discard decimal parts: e.g. Int (123.45) = 123; Int ("123") results in 123. float(x): converts x to a floating point number, incrementing the decimal part, such as float(12) results in 12.0; Float ("1.23") results in 1.23Copy the code

The End of it

About the number type xiaobian is introduced here, if you encounter the knowledge related to it later, xiaobian will supplement oh. If this article has been helpful to you, you may be reviewing Python for an exam. I hope you can continue to support this album and support Python