Self-developed artificial intelligence ------ variable understanding and operations in Python,
Today, I will introduce the Number variable in python, which is somewhat different from c ++ and java. Let's introduce it to you as follows:
In python, you do not need to declare the variable type, but you need to assign a value to the variable before using it. It is meaningless to have no variable worth it, and the compiler will not pass
I. Integer ----- int:
The usage of int in python is roughly the same as that in c ++:
A = 12
Print
The printed result is: 12.
Here I will first introduce several functions
Type (): return the Data type in parentheses.
A = 'hello'
Print type ()
>>>> <Type 'string'>
Len (): returns the length of the variable in parentheses.
Note: The len () method cannot be of the int type.
A = 'Hello world'
Print len ()
>>> 11
Ii. Floating Point ------ float
Float is composed of integer and decimal parts. It can also be expressed by scientific notation.
A = 1.23
Print type ()
>>< Type 'float'>
Iii. Plural
The plural part is composed of the real number and the virtual number. a + bj or comple (a, B) can be used. The real part a and the virtual Part B of the plural are float.
Iv. Data Type Conversion
Int (x): converts x to an integer.
Float (x): converts x to a floating point number.
Complex (x): converts x to a plural number. The real part is x, and the virtual part is 0.
A = 1.23
Print complex ()
>>> (1.23 + 0j)
Complex (x, y): converts x and y into a plural number. The real number is x, and x and y are numeric expressions.
5. Constants
Python has two common constants, PI and E.
PI: mathematical constant pi (circumference rate)
E: mathematical constant e. It is a natural number.
Now, today's introduction is over, hoping to help you.