在 python 中的 __init__ 构造函数中定义一个函数是什么意思?

What does defining a function with in the __init__ constructor in python mean?

刚刚看到下面的代码,想知道里面的函数是什么 __init__函数表示

def __init__(self):
    def program(percept):
        return raw_input('Percept=%s; action? ' % percept)
    self.program = program
    self.alive = True

这个代码

class Foo:
    def __init__(self):
        def program(percept): 
            return raw_input('Percept=%s; action? ' % percept)
        self.program = program

A​​FAIK,实际上与 self.program = program 完全相同。

class Foo:
    def __init__(self):
        pass

    def program(self, percept): 
        return raw_input('Percept=%s; action? ' % percept)

我能看到嵌套一个函数的唯一原因是,如果您只是使用该函数在构造函数中进行一些初始化,但不想在 class 上公开它。