Today, I would like to introduce you to the number variable in Python, which is somewhat different from C++,java, let's introduce:
It is not necessary to declare a variable type in Python, but it is not worthwhile to assign a value to a variable before it is used, and the compiler will not pass
One: integer-----int:
The use of int in Python is roughly the same as C + +:
A=12
Print a
The result of the printing is: 12
Here I would like to first introduce you to a few functions
Type (): Returns the data type in parentheses
A= ' Hello '
Print type (a)
>>>><type ' String ' >
Len (): Returns the length of the variable in parentheses
Note: Using the Len () method is not possible with the int type
A= ' Hello World '
Print Len (a)
>> >11
Two: Float type------float
Floating-point types consist of integers and fractional parts, or they can be represented by scientific notation
a=1.23
Print type (a)
>> <type ' float ' >
Three: plural
Complex numbers are composed of real and imaginary parts, which can be a+bj or comple (A, B), and the real and imaginary parts of the complex numbers are floating point types
Four: Data type conversions
int (x): Converts x to an integer
Float (x): Converts x to a floating-point number
Complex (x): Converts x into a complex number, the real part is x, and the imaginary part is divided into 0
a=1.23
Print Complex (a)
>>> (1.23+0J)
Complex (x, y): Converts x and y to a complex number, the real part is divided into x,x and y is a numeric expression
V: constant
There are two more common constants in Python, Pi and E
Pi: Mathematical constant Pi (π)
E: Mathematical constants E. i.e. Natural number
Well, today's presentation is over and I hope to help you.
Self-hing Artificial intelligence------The variable cognition and operation of Python language