라벨이 collections.abc인 게시물 표시

파이썬[Python]: collections.abc - Callable 클래스

collections.abc 모듈 - Callable 클래스(class) /// 설명 Abstract Base Class 입니다. # Abstract Methods : __call__ # Minix Methods : None ※ 형식 class collections.abc.Callable /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 from  collections.abc  import  Callable # ABC(Abstract Base Class): Callable # Abstract Methods : __call__ # Minix Methods : None   # first way # A newly written class can inherit directly from one of the abstract base classes. class  MyClass1(Callable):    # 상속      def  __init__( self ):     # 생성자(Extra method)          pass        def  __call__( self ):     # 필수(abstract method)          return   1     print (issubclass(MyClass1, Callable))   # True test_instance  =  MyClass1() print (isinstance(test_instance, Callable))   # True   # second way # Existing classes and built-in classes can be registered as “virtual subclasses” of the ABCs. # the full API including all of th