内外函数问题, 问第二次出现myfunc()的作用,没有为啥不能运行内函数?

x = "awesome"


def myfunc():
  x = "fantastic"
  print("Python is " + x)

myfunc()

print("Python is " + x)



这里面的外函数(第2个)  “myfunc()”       是干什么用的不懂


没有问题,myfunc()是函数调用,你写一句print也是函数调用
你myfunc()函数在定义的时候,里面有了一个局部变量x,这个x覆盖掉了外面的x,所以打印Python is fantastic,而局部变量只在函数内部生效,不会修改全局变量,所以你再print一次还是Python is awesome
img