python type annotation
-
type annotationpython 기초 2023. 1. 24. 12:13
python / matlab과 같은 동적 타입 언어를 주로 쓰다보면, 만들때는 응당 그러려니 하고 만들었던 함수가 나중에는 헷갈리는 경우가 많다. 주석도 중요하지만, type annotation 또한 중요해보인다. def int_mul(a:int,b:int): return a*b def float_mul(a,b): return a*b print(int_mul.__annotations__) print(float_mul.__annotations__) 위의 int_mul 함수와 같이 입력 변수 뒤에 :type 으로 input에 대한 annotation을 해주면 된다. 이렇게 되면 아래에서 함수명.__annotations__ 를 통해 호출해서 각 변수의 type을 알수 있다. 협업시 중요한 기능 중 하나라 할 ..