Python study notes (number type)

Python includes three types of numbers: integer types , floating point types , and complex number types .
Integer type : Consistent with the concept of integer in mathematics, there is no limit to the range of values.
Floating point type : Number with decimal point and decimal. There is a limit to the range of floating-point numbers in Python, and there are limits to decimal precision. This limit is related to different computer systems.
Complex number type : consistent with the concept of complex numbers in mathematics, z = a + bj, a is the real part, b is the imaginary part, a and b are both floating-point types, and the imaginary part is identified by j or J. For complex numbers z, you can use z.real to get the real part and z.imag to get the imaginary part.
The relationship of the number types
There is a gradually "expanded" relationship among the three types:
integer-> floating-point-> complex (integer is a special case of floating-point numbers, floating-point number is a special case of complex numbers)
Mixed operations can be performed between different types of numbers, and the result after the operation is the widest type.
Three types can be converted to each other, functions: int (), float (), complex ().
Number type judgment
function: type (x) returns the type of x, suitable for all types of judgment.
Numeric operations
Insert picture description here

Published 48 original articles · Like 25 · Visit 2453

Guess you like

Origin blog.csdn.net/qq_43628959/article/details/96500561