name = "head first python"def what_happens_here(): print(name) 1 name = "python" 2 name = name + "is a great book!" print(name)what_happens_here()print(name)
这里行1 会出错,原因,行2中对name进行赋值,所以name是局部变量,然后行1中,在未赋值前就先引用 ,所以出错