Suppose such a function:
In [56]: def add_numbers(x, y): return x + y
当我不使用括号时,它的含义会发生改变。
In [57]: add_numbers
Out[57]: <function __main__.add_numbers(x, y)>
这里的__main__
是什么意思?
它不属于add_numbers
的标准或元属性:
In [59]: "__main__" in dir(add_numbers)
Out[59]: False
def main(): def add_numbers(x, y): return x + y print(add_numbers) if __name__ == '__main__': main()
我得到了这个输出:<function main.<locals>.add_numbers at 0x7f21d39f40d0>
- Abhishek Arya