What is the benefit to define a function in a function in python?

后端 未结 3 839
名媛妹妹
名媛妹妹 2021-01-31 03:15

I encountered this piece of python code (pasted below) on effbot and I was wondering:

Why defining a function within a function?

import          


        
3条回答
  •  后悔当初
    2021-01-31 03:43

    Often the main reason of such code is function closures. It is powerful thing that is applicable not only to Python. E.g. JavaScript gains a lot from them.

    Some points about closures in Python - closures-in-python.

提交回复
热议问题