Thursday, May 7, 2020

Numbers in Python

Numbers  are immutable  ( we cannot change the values ).

[ once the object is created and the value is stored, we cannot change the value ].



[ When you try to change the value, it creates the new object and it will get a separate reference and it is assign to the same variable ].



Supports four types of numbers 


- INTEGERS

             -   PLAIN INTEGERS
             -   LONG


 - FLOATING POINT REAL NUMBERS

 - COMPLEX NUMBERS


PLAIN INTEGERS

        - Simple values
        - Universal numeric

x=1              ---------->             decimal
x=0              ----------->            octal (base 8)
x=0x or 0X  ----------->            hexa decimal  (base 16)


LONG 

         It is a special, range is not predefined and it is completely depends on virtual memory.

How to represent a long value ?

suffix can be lower case l or the upper case L.

x=9999999999L or x=999999999l

FLOATING POINT REAL NUMBERS 

One of the numbers supported by python

( we have similar things in the 'C' language called double datatype, we have seen ( double precision point value it can store ) ).

x=1.25
y=1.45E+12  ( E  -----> Exponent value )
z=float(10)

Different floating values we can use in different purposes.

[ this is equivalent to double datatype in 'C' language ]

Complex Numbers 

very special features in python.

x=1+2J ( complex number assigned to x )

print(x.real);
print(x.imag);

we can also complex conjugate.



















No comments:

Post a Comment