Typing2 1007. Volume of a Cuboid Bob needs a fast way to calculate the volume of a cuboid with three values: the length, width and height of the cuboid. Write a function to help Bob with this calculation. Solution: from typing import List, Callable def get_multiply(args: List[int], result:int = 1) -> int: for i in args: result *= i return result def get_volume_of_cuboid(length: int, width: int, height: int, func: Callable = get.. 2022. 10. 8. Python _ Protocol로 인터페이스 만드는 방법 Python에서 인터페이스를 구현하는 방법에는 여러 가지가 있지만 이번 글에서는 Protocol을 이용한 방법을 소개한다. 인터페이스란? 쉽게 말해 외부와 소통하기 위해 필요한 메서드를 정의한것이다. 하위 모듈들은 해당 인터페이스에 맞춰 기능을 구현한다. Protocol 사용법 아래 코드를 보자. from typing import Protocol class 감정(Protocol): def 기쁘다(self) -> str: ... def 슬프다(self) -> str: ... class 사람: def 기쁘다(self) -> str: return "기뻐!" def 화나다(self) -> str: return "화나!" class 사회생활: def 시작(self, 사람: 감정) -> None: self.사람 =.. 2022. 8. 16. 이전 1 다음