본문 바로가기

Python

[Python] Function Annotation

함수의 매개변수 및 리턴 타입에 대해 주석처리 가능

# 매개변수 뒤에 :expression
# 함수명 뒤에 -> expression
def Func1(arg1:expression) -> expression :
	//To-DO
class Cal:
    def __init__(self, b, c) -> None:
        self.b = b
        self.c = c
    
    #annotation으로 string을 넣던지 변수 타입을 넣던지 상관 x
    #string 넣으면 빨간 줄이 쳐지지만 실행 가능
    def setDataFunc(self, b: 'please int', c: int) -> None:
        self.b = b
        self.c = c
    
    def printFunc(self):
        print(self.b)
        print(self.c)

a = Cal([1,2], 65)

a.setDataFunc(122, 53)
a.printFunc()
반응형

'Python' 카테고리의 다른 글

[Anaconda] Anaconda 가상환경 생성 방법  (0) 2022.01.28
[Python] 클래스 상속 / 오버라이딩 / 클래스 변수  (0) 2022.01.22
[Python] 생성자(Constructor)  (0) 2022.01.20
[Python] 클래스 (class)  (0) 2022.01.20
[Python] print()  (0) 2022.01.20