int,float and boolean numberic Type in Python part 9 | Numeric Type - Int, Float, Long, Complex




Numeric Type - Int, Float, Long, Complex

There are four different numerical types: plain integers, long integers, floating point numbers, and complex numbers. In addition, Booleans are a subtype of plain integers. Plain integers (also called simply integers) are implemented using long periods of time in C, giving them an accuracy of at least 32 bits. Long integers have unlimited precision. The floating point number is implemented using a double in C. As long as you know the machine you are working with, all bets are off on their accuracy.

Complex numbers have a real and imaginary part, implemented using a double in each c. To extract these parts from a complex number z, use z.real and z.imag.

Numerals are created as a result of numeric literal or implicit functions and operators. As long as the value they represent is not too large, literals with integer integers (including hex and octal numbers) get plain integers, in which case they make an integer. Integral literal yields with an "L" or "L" suffix are long integers ("L" is preferred because "1L" looks too much like eleven!). Numeric literal floating point numbers with a decimal point or an exponential symbol produce numbers. Applying a numeric literal "J" or "J" gives a complex number with a zero real part. A complex numeric literal is the sum of a real and an imaginary part.

Python supports fully mixed arithmetic: when a binary arithmetic operator has operands of different numeric types, the operand with the `` narrower '' type is widened to another, where the plain integer is longer than the integer. Is narrower than the floating point is narrower than complex. Comparisons between mixed-type numbers use the same rules. 2.6 Constructors int (), long (), float (), and complex () can be used to produce specific types of numbers.

All numeric types (except complex) support the following functions sorted by ascending priority (operations in the same box have the same priority; all numeric functions have higher priority than operations):

Operation              Results                               Notes
x + y                 sum of x and y
 x - y                   is x and y
x * y                x and y products
x / y              quotient of x and y                        (1)
x // y            (floored) quotient of x and y         (5)
x% y             remaining x / y                              (4)
-x x              denied
+ x x             unchanged
abs (x)         The absolute value or magnitude of x
int (x)            x converted to integer                   (2)
Long (x)       x is converted to long integer        (2)
Float (x)        x converts to floating point

complex (re, im) A complex number with real part re, imaginary part im. im zero lapse.
c.conjugate () conjugate of complex number c
divmod (x, y) pair (x // y, x% y) (3) (4)
pow (x, y) x to power y
x ** y x to power y

Post a Comment

0 Comments

Search This Blog