Type Annotation (4) - Union
Union Type 특정 변수의 자료형이 여러 type 중 하나이면 문제 없을 때, 가능한 type의 범위를 Union을 통해 나타낼 수 있다. # https://mypy.readthedocs.io/en/stable/kinds_of_types.html import numpy as np from typing import Union, List arr1: Union[List, np.array] = [1,2,3] def foo(arr: Union[List[int], np.array[int]) -> int: return arr[0] print(foo(arr1)) # 1
개발/python-객체지향프로그래밍(OOP)
2022. 5. 22. 20:52