L2 PythonBasics
L2 PythonBasics
and Practise a p
gan
th u
M u
a n
ath
a n
a m
R
• int
h y
at
• float an
a p
u g
uth
• complex th a n M
n a
m a
• bool R a
• string
• bytes
Demo using
at h
a p
gan
th u
u
L2_demodatatypes.py
n M
th a
n a
m a
R a
• a = 3; b = 3 # semicolon as a separator
• a, b = 3, 4.45 # This is a very interesting way.
• + , - and * are as in C
h y
at
• / is True division (No integer division as in aC).
na p 3/5 will not yield 0.
u g
uth
• ** is the exponentiation i.e. a ** b ishaequal
t
n M to ab
n a
m a
• // return quotient (without theRafractional part, like a ‘floor’ operation)
h y
pat
a
gan
th u
M u
a n
ath
a n
a m
R
y
Demo using
at h
a p
gan
th u
u
L2_Operatordemo1.py
n M
th a
n a
m a
R a
• 10 // 3
h y
at
• -10 // 3 an
a p
u g
uth
• 10 // -3 th a n M
n a
m a
• 10 % 3 R a
• -10 % 3
• 10 % -3
• Mixed mode
h y
• op. between int and float will yieldanfloat ap
a t
u g
• op. between int and complex a n M u t
willh
yield complex
a th
• op. between complexRaand
m a n float will yield complex
• Convert one to another using built-in functions int( ), float( ),
complex( ), bool( )
Built-in math functions
a = 1+ 2j
h y
print(a.real) # Data pat
a
gan
th u
u
print(a.imag) # Data a n M
ath
a n
a m
print(a.conjugate()) # Function R
Demo using
at h
a p
gan
th u
u
L2_Complexdemo.py
n M
th a
n a
m a
R a
import math
h y
pi = math.pi; r = 5 pat
a
gan
th u
u
area = pi * r ** 2 a n M
ath
a n
a m
print(area) R
area1 = math.pi * r ** 2
print(area1)
Demo using
at h
a p
gan
th u
u
L2_import_example.py
n M
th a
n a
m a
R a