목록Programming/Python 11
2030 Engineer
LBYL : Look Before You Leap 뛰기 전에 살펴보라 (돌다리도 두들겨 보고 건너라) EAFP : Easier to Ask for Forgiveness than Permission 허락보다 용서가 쉽다! (일단 먼저 빨리 실행하고 문제가 생기면 처리한다. 1 2 3 4 if isinstance(name, Account): self.names.append(name) else: print("이건 계좌에 들어가지 못하는 이름입니다.") LBYL식이면 이렇게 만약 ~라면 실행하고 아니면 안된다고 출력할께라는 식이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def add_shape(self, shape: Shape): self.shapes.append(shape) def ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 from abc import ABC, abstractmethod class Message(ABC): @abstractmethod def print_message(self) -> None: pass class Sendable(ABC): @abstractmethod def send(self, destination: str) -> None: pass class Email(Message, Sendable): def __init__(self, content, user_email): self.content = content self.user_email = user_email def print_message(self..
추상 클래스는 서로 관련있는 클래스들의 공통 부분을 묶어서 추상화한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from abc import ABC, abstractmethod class Vehicle(ABC): @abstractmethod def start(self): """추상 메소드 start: 교통 수단의 주행을 시작한다""" pass @property @abstractmethod def speed(self): """변수 _speed(교통 수단의 속도)에 대한 추상 getter 메소드""" pass def stop(self): """일반 메소드 stop: 교통 수단의 속도를 0으로 바꾼다""" self.speed = 0 Car, Bicycle, Train 등..