2. What?
How?
Why?
data = [
2, True]
age = 20
print(age)
me = “Nard”
print(
“Hi”, me)
Menard Maranan
-Stores Data
Values
-Use Alias for
Naming.
-Pass Data
Values
-Call name to
Use on code
-Shorter
Codes
-Saves Time
Menard Maranan
https://www.youtube.com/channel/UC28oX1455dR2OF72o1DU80w/
4. if else
while loop
for loop
sunny = True
if sunny:
print(“Need Hat”)
else:
print(“No need”)
num = 10
while num != 0:
print(num)
num -= 1
for x in range(10):
print(x)
Menard Maranan
-Logical
Control Flow
-Uses
Condition/s
-Uses
Condition/s
to loop on a
code/s
-Uses
Iteration to
Loop on a
code/s
Menard Maranan
https://www.youtube.com/channel/UC28oX1455dR2OF72o1DU80w/
6. except
try:
answer = 4 / 0
except ZeroDivisionError:
print(“INVALID”)
else:
print(answer)
Menard Maranan
Menard Maranan
https://www.youtube.com/channel/UC28oX1455dR2OF72o1DU80w/
finally:
print(“Always Executed”)
else
-Codes written
inside were to
be validated
if no error/s.
-When an error
(exception) is
raised, codes
it hold were
executed.
-If no error
(exception) is
raised, codes
it hold were
executed.
-Codes it hold will
always be executed
regardless if there’s
an error or none.
try
finally
7. What?
How?
Why?
def greet(name):
return f‘Hi {name}!’
print(greet(“Menard”))
>>>Hi Menard!
print(greet(“Michael”))
print(greet(“Leonel”))
print(greet(“Melanie”))
print(greet(“Leonard”))
Menard Maranan
-Takes input
(or not),
spits output
(or not)
-Independent
from a Class.
-Create it &
Call it; with
or without
argument
(input); as
many times
as you want
-To Organize
Codes.
-Saves time
from
repeated
coding.
Menard Maranan
https://www.youtube.com/channel/UC28oX1455dR2OF72o1DU80w/
8. class
method
inheritance
class Compute(Calculate):
def __init__(self, x, y):
self.x = x
self.y = y
print(Compute(9, 2).root())
Menard Maranan
-Also called as
Objects
-A collection
of methods
-Organizes
codes
Menard Maranan
https://www.youtube.com/channel/UC28oX1455dR2OF72o1DU80w/
-Similar to
Functions
-Dependent
to a Parent
Class
-Used to pass
codes from
one class to
another
class Calculate:
def __init__(self, x, y):
self.x = x
self.y = y
def root(self):
return pow(self.x, (1 / self.y))
class Calculate:
def __init__(self, x, y):
self.x = x
self.y = y