📜  在 python 代码示例中从函数外部访问变量

📅  最后修改于: 2022-03-11 14:46:25.775000             🧑  作者: Mango

代码示例1
# for accessing a variable from outside the function then create that variable
# as an attribute of the function
def hi():
    # other code...
    hi.bye = 42  # Create function attribute.
    sigh = 10

hi()
print(hi.bye)  # -> 42