junior interview questions OOP explained
Procedural Programming:
(what we've been doing until day 15)managing the whole relationships in one file, getting more complex.
We can split a larger task into smaller pieces, which is reusable when we need the same functionality.
Make it scalable for a larger project.
easy for maintainance
Object = function + data
모듈: 특정 기능을 .py 파일 단위로 작성한 것입니다.
패키지: 특정 기능과 관련된 여러 모듈을 묶은 것입니다. 패키지는 모듈에 네임스페이스(namespace, 이름공간)를 제공합니다.
파이썬 표준 라이브러리: 파이썬에 기본으로 설치된 모듈과 패키지, 내장 함수를 묶어서 파이썬 표준 라이브러리(Python Standard Library, PSL)라 부릅니다.
File unit containing functions: easy to maintain and reusable
Module includes variables, functions, and classes.
import
from import
e.g.
from turtle import Turtle as tur
import turtle as tur
timmy = tur()
timmy.forward(100)
a blueprint that can generate multiple objects
-Attributes: variables associated with the model. data being able to keep track of.
-Methods: functions.
-Class naming: Pascal case -> first of the each letter capitalised
to differentiate it from names of variables and functions with underscores.
e.g. car = CarBlueprint()
Object Class
1) obj car has attributes:
speed = 0
fuel = 32
car.speed
Obj Attribute
--------------------
2) obj car has methods:
def move():
speed =60
car.move()
Obj Method
PyPI : libraries, packages, documentation
PrettyTable
from prettytable import PrettyTable
table = PrettyTable()
table.add_column("Pokemon Name", ["Pikachu", "Squirtle", "Charmanderr"])
table.add_column("Type", ["Electric", "Water", "Fire"])
table.align["Type"] = "c"
table.align["Pokemon Name"] = "l"
print(table)
+--------------+----------+
| Pokemon Name | Type |
+--------------+----------+
| Pikachu | Electric |
| Squirtle | Water |
| Charmanderr | Fire |
+--------------+----------+
Documentation
menu = Menu()
coffee_maker = CoffeeMaker()
money_machine = MoneyMachine()
is_on = True
while is_on:
options = menu.get_items()
choice = input(f"What would you like {options}?: ")
if choice == "report":
coffee_maker.report()
money_machine.report()
elif choice == "off":
is_on = False
else:
drink = menu.find_drink(choice) #choice will be drink's name #find_drink returns MenuItem obj order_name
#.MenuItem(latte)
if coffee_maker.is_resource_sufficient(drink):
if money_machine.make_payment(drink.cost): # menu.find_drink.cost
#menu.find_drink returns MenuItem object, MenuItem.cost gives price of the drink
coffee_maker.make_coffee(drink)
today's quote:
It's going to become a word that's going to be in your dictionary.