first experience python - numeric type

A numerical type

In the world of Python, the most commonly used data types, there are three - string (str) , integer (int) and floating point (float) .

As long as single quotes or double quotes content, whether there is a number or Martian, etc., it is the string type! For example, my name:my_name = '小陈'

Integer as our math textbook definition: is a positive integer, negative integer and collectively zero, no decimal point. For example, my age:my_age = 18

Float is there is a decimal point. For example, my weight:my_weight = 45.5

Tips: integer is without a decimal point, floating-point number is a number with a decimal point.

The computer is essentially a machine to do the calculation, its main task is to deal with various data. We can now store various types of data, then calculates how it?

We can use the Python code to common numerical computation, you can think of it as a powerful calculator. Below is the Python numeric operators (also referred to as arithmetic operators )

These operators and mathematics are similar, there are only different in form, the role is the same

 Second, the priority calculation

Python world precedence of operations, and we usually mathematics of calculating priority is the same.

When it comes to rabbit problems, most notably Fibonacci study of.

Fibonacci, medieval Italian mathematician, was the first Western study Fibonacci number of people. Fibonacci in the "calculation of the book" presents an interesting rabbit problem . In general, the rabbit in two months after birth, have the ability to reproduce, a pair of rabbits each month to give birth to a pair of small rabbit. If all rabbits do not die, then a year later the number of rabbits can breed?

The figure is derived Fibonacci sequence, also called Fibonacci numbers :

Think about it: You can find a number of laws that deed Fibonacci do, guess how much the first 13 months of the rabbit do?

 

Third, the data type conversion

We can put directly to the integer and floating point operations together, then what if the integer and string concatenation will happen then? Yes, the program will complain.

 Program error prompt must be read carefully, it can effectively help us find the problem. Error prompt us here: In the second line of code, not coupled with the strings and integers (added).

Tips: If you do not know what a data type, you can type () to see its type functions such as Print (of the type (2.3)) .

So, this time you have to need to use the data type conversion functions , this is a common three conversion functions

 

Guess you like

Origin www.cnblogs.com/free-1124/p/11331845.html