#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목[re]사용자 지정함수 입력변수 int설정2022-03-22 18:28
작성자
def calcAge(now_age, now_year, future_year):

    assert type(now_age) == type(0)
    assert type(now_year) == type(0)
    assert type(future_year) == type(0)

    future_age = now_age + (future_year - now_year)

    return future_age


위와 같이 기존의 자가 진단에 활용한 assert를 사용하여 원하는 type이 아니면 함수 동작을 멈추게 할 수 있습니다.

동작이 멈추는 것이 싫으면 if문으로 예외 처리를 하실 수도 있습니다.

댓글