float data type:
We can use float data type
to represent floating point values (decimal values)
Eg: 
f=1.234 
type(f) 
<class ‘float’>
We can also represent
floating point values by using exponential form (scientific notation)
Eg: 
f=1.2e3 
print(f) 
1200.0 instead of 'e' we can
use 'E'
The main advantage of
exponential form is we can represent big values in less memory.
***Note: We can represent
int values in decimal, binary, octal and hexadecimal forms. But we can
represent float values only by using decimal form.
Eg: 
>>> f=0B11.01 
File
"<stdin>", line 1 
f = 0B11.01 
^ 
SyntaxError: invalid syntax 
>>> f=0o123.456 
SyntaxError: invalid syntax 
 >>> f=0X123.456 
SyntaxError: invalid syntax
Complex Data Type:
A complex number is of the
form a and b
contain integers or floating point values
Eg: 
3+5j 
10+5.5j 
0.5+0.1j
In the real part if we use
int value then we can specify that either by decimal,octal,binary or hexadecimal form. But imaginary part should be specified only by using decimal
form. 
 >>> a=0B11+5j 
 >>> a 
 (3+5j) 
 >>> a=3+0B11j 
 SyntaxError: invalid
syntax 
Even we can perform
operations on complex type values. 
 >>> a=10+1.5j 
 >>> b=20+2.5j 
 >>> c=a+b 
 >>> print(c) 
 (30+4j) 
 >>> type(c) 
 <class 'complex'>
Note: Complex data type has
some inbuilt attributes to retrieve the real part and imaginary part
c=10.5+3.6j
c.real--->10.5 
c.imag--->3.6
We can use complex type
generally in Scientific Applications and Electrical engineering Applications.
 

 
No comments:
Post a Comment