항상 감사하며 마633

고정 헤더 영역

글 제목

메뉴 레이어

항상 감사하며 마633

메뉴 리스트

  • 홈
  • 태그
  • 방명록
  • 분류 전체보기 (93)
    • 개발 (59)
      • 개발환경설정 (6)
      • python-심화(Advanced) (23)
      • python-객체지향프로그래밍(OOP) (21)
      • python-병렬처리 (7)
      • python-속도향상(optimization) (2)
    • Study (16)
      • DeepLearning from scratch (16)
    • paper review (15)
      • NLP (15)
    • Google Machine Learning Boo.. (3)

검색 레이어

항상 감사하며 마633

검색 영역

컨텐츠 검색

개발/python-객체지향프로그래밍(OOP)

  • access modifier (접근지정자)

    2022.05.27 by Matthew0633

  • Context Manager

    2022.05.27 by Matthew0633

  • Mix-in Class

    2022.05.25 by Matthew0633

  • Duck typing 과 Nominative typing, Structure typing

    2022.05.25 by Matthew0633

  • Type Annotation (9) - Generic Type

    2022.05.25 by Matthew0633

  • Type Annotation (8) - Final Type

    2022.05.23 by Matthew0633

  • Type Annotation (7) - Type alias

    2022.05.23 by Matthew0633

  • Type Annotation (6) - Class

    2022.05.23 by Matthew0633

access modifier (접근지정자)

access modifier (접근지정자) 파이썬에서는 class 변수나 instance 변수를 정의할 때, 기본적으로 public 한 성질을 가지고 있고, protected, private 에 대한 강제성이 없다. 이와 관련된 python 공식문서의 일부분이다. (9.6. Private variables) “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) sho..

개발/python-객체지향프로그래밍(OOP) 2022. 5. 27. 23:57

Context Manager

Context Manager 개념 context manager 란 특정 행동을 할 때 항상 일정한 런타임 환경을 만들어주기 위해 특정 행동에의 진입과 종료를 관리해주는 객체 이다. with 구문을 통해 실행되어, 원하는 타이밍에 정확하게 리소스를 할당하고 제공하는 역할을 한다. (python 공식 document) A context manager is an object that defines the runtime context to be established when executing a [with] statement. The context manager handles the entry into, and the exit from, the desired runtime context for the execu..

개발/python-객체지향프로그래밍(OOP) 2022. 5. 27. 23:57

Mix-in Class

믹스인(mix-in)은 다른 클래스들에서 공통적으로 사용할 수 있는 메서드를 모아 놓은 클래스이다. 파이썬에서 믹스인은 자체적인 인스턴스 속성을 가지고 있지 않아 __init__ 메서드 또한 구현하지 않는다. 아래 예시에서, 문자열에서 이메일 정보를 제거하는 메소드를 가진 믹스인을 정의하였다 (TextProcessMixIn). 텍스트를 담을 수 있는 Text class 를 정의하고, 이 둘을 상속받아, 각각 뉴스기사와 SNS 텍스트를 전처리를 수행하는 class 를 정의할 수 있다 (ArticleProcessor 와 SocialMediaProcessor). 이 둘은 상속받은 믹스인 class 의 이메일 제거 메소드를 사용할 수 있다. class TextProcessMixIn: def remove_emai..

개발/python-객체지향프로그래밍(OOP) 2022. 5. 25. 23:49

Duck typing 과 Nominative typing, Structure typing

타이핑 방식은 ‘타입이 같은가’, ‘타입이 호환가능한가’ 를 체크하기 위한 방식이다. 이러한 타이핑 방식에는 Nominative typing, Structure typing 방식이 있다. 그리고 내가 주로 사용하는 파이썬에서 매우 자주 사용되는 Duck typing 까지 살펴보고자 한다. Nominative typing (명시적 타이핑) In computer science, a type system is a nominal or nominative type system (or name-based type system) if compatibility and equivalence of data types is determined by explicit declarations and/or the name of t..

개발/python-객체지향프로그래밍(OOP) 2022. 5. 25. 23:49

Type Annotation (9) - Generic Type

Generic Type A type that can be parameterized; typically a container class such as list or dict. Used for type hints and annotations. 파이썬 공식문서에서 는 generic type 을 위와 같이 설명하고 있다. 파이썬 내에서 Generic type class 는 type 을 파라미터화하여, 인자로 받을 수 있다. 인자로 받은 type 을 공유하는 지역변수 간에는 동일한 type 으로 표시될 수 있다. 이는 type hint와 annotation 을 위해 사용된다. 아래 예시를 보자. Robot class 를 정의할 때 T, K 라는 2개의 type 을 인자로 받는 Generic type 을 상속받는다..

개발/python-객체지향프로그래밍(OOP) 2022. 5. 25. 23:49

Type Annotation (8) - Final Type

Final Type 변수에 대해 한번 값이 정해지고, 이후 값이 변경되지 않는 상수임을 나타낼 때, Final 을 사용할 수 있다. from typing_extensions import Final BATCH_SIZE: Final = 128

개발/python-객체지향프로그래밍(OOP) 2022. 5. 23. 14:20

Type Annotation (7) - Type alias

변수의 사용가능한 type 이 많아 가독성이 떨어질 경우, alias 를 부여할 수 있다. # https://mypy.readthedocs.io/en/stable/kinds_of_types.html#type-aliases from typing import Union, List, Tuple, Dict, Optional # type alias Type_x = Union[int, Union[List[str], Tuple[int, ...]], Optional[Dict[str, float]]] x: Type_x = 17 def cal(v: Type_x ) -> Type_x : return v Dict alias : TypedDict dict 의 경우는 class 를 활용하여 type alias 를 정의할 수 있다..

개발/python-객체지향프로그래밍(OOP) 2022. 5. 23. 14:20

Type Annotation (6) - Class

변수의 class 를 hint 로 제공할 경우, 단순히 class명을 변수명 옆에 써주면 된다. # class types class Hello: def world(self) -> int: return 7 # (1) 변수 정의 시 class hint myhello: Hello = Hello() # (2) 함수 인자에서 class hint def foo(ins: Hello) -> int: return ins.world() print(foo(hello)) # 7

개발/python-객체지향프로그래밍(OOP) 2022. 5. 23. 14:20

추가 정보

인기글

최신글

페이징

이전
1 2 3
다음
TISTORY
항상 감사하며 마633 © Magazine Lab
페이스북 트위터 인스타그램 유투브 메일

티스토리툴바