Professional Documents
Culture Documents
firmtech.in 2
Variable
23
Var_A = 23
id(Var_A) 140719346777856
Var_C = 15
id(Var_C)
Python gives the reference of the
object(value) to the variable
firmtech.in 5
Data Types
• Classification Of The Type Of Values That Can Be
Assigned To Variables
• Operations Are Performed Based On The Values
• Numeric -- int, float, complex
• Sequence -- list, tuple, range
• Text sequence --str
• Mapping --dict
• Set Type – set, frozenset
• Binary sequence – byte, bytearrays
• Boolean
firmtech.in 6
Int
type() – to know the class c = 0b01010101
int are whole numbers, print(type(c))
can be positive, negative d = 0b 11110000
or zero
print(type(d))
a=5
e = 0xface
print(type(a))
f = 0xface
b=0
print(type(e));
print(type(b) print(type(f ))
int can also be represented
Base conversion – bin(),
as binary, octal, and hex(), oct()
hexadecimal with prefix
0b,0B, 0o,0O, 0x,0X Print(bin(a)); print(hex(a))
Print(oct(a)); print(bin(e))
firmtech.in 7
float
floating point contains a decimal point,
expressed in exponential form also
c = 34.6 ; d = -45.765
e = 356.3e5 ; f = 3456.6e-7
g = 123e4 ; h = 123e-4
print(type(c)) ; print(type(d))
round()
round(123.456789,4)
round(h, 3)
firmtech.in 8
Complex
complex numbers are written in the form a + bj,
where a is the real part and b is the imaginary part
x = 10 + 20j
y = 123.456 + 678.345j
z = 123e4 - 567e-4j
w = 0b1010101010 + 123.456767J
print(type(y)
to get the real and imaginary parts
print(z.real)
print(z.imag)
firmtech.in 9