passing object to object

This question already has an answer here:

  • Can you explain closures (as they relate to Python)? 13 answers

  • What you're encountering is a closure.

    When you write part_string(my_indexes) you're creating a new function, and upon calling it, you use the old variables you gave to part_string together with the new variables given to function_instance .

    You may name the inner function whatever you want, and there is no convention. ( obj is used in here but it can be pie . There are no conventions for this except func for function closures (decorators).

    If you wish to pass two variables to the function, you may define two variables to the g(obj) function:

    def g(var1, var2):
        ...
    

    Here's some more info regarding closures in python.

    链接地址: http://www.djcxy.com/p/51112.html

    上一篇: python:绑定是如何工作的

    下一篇: 将对象传递给对象