新课程知识的引入:python作用域
#python中无块级别作用域 if 1 == 1 : name = ‘alex‘ print(name) for i in range(10): name = i print(name) #python中以函数为作用域 def func(): name = ‘alex‘ print(name) #程序执行结果 # Traceback (most recent call last): # File "D:/PythonS13/Day10/С????1_python??????.py", line 22, in <module> # print(name) # NameError: name ‘name‘ is not defined
时间: 2024-12-28 11:07:57