local variable 'a' referenced before assignment

代码如下:
def a():
    aa = '123'
    return aa

def main():
    a = a()
    print a

main()
>>>UnboundLocalError: local variable 'a' referenced before assignment

这样的话就没问题:
def a():
    aa = '123'
    return aa

def main():
    # 变量不是a就行
    a2 = a()
    print a2

main()
>>>'123'

你可能感兴趣的:(python)