ruby-jieun 2023. 1. 7. 23:33

 

 

중첩함수

 


 

 

중첩함수

  • 함수안에 또 다른 함수가 있는 형태이다.
def out_funtion():
    print('out_function called!!')

    def in_funtion():
        print('in_function called!!')

    in_funtion()

out_funtion()
out_function called!!
in_function called!!

 

  • 내부 함수를 함수 밖에서 호출할 수 없다.
def out_funtion():
    print('out_function called!!')

    def in_funtion():
        print('in_function called!!')

    in_funtion()

in_funtion()
NameError: name 'in_funtion' is not defined. Did you mean: 'out_funtion'?