关于Python中本地和全球变量的概念
请检查下面的代码。
x = 10
z = 30
def Rohan():
y = 15
x = 20
print(x,y,z)
global z
global x
z += 5
print (x,y,z)
Rohan()
在调用Rohan()时,我会遇到一个错误,上面写着“ syntaxerror:name z'在全局声明之前使用 “
请帮助我解决全局变量和本地变量的概念,以及导致错误的原因。
please check the code below.
x = 10
z = 30
def Rohan():
y = 15
x = 20
print(x,y,z)
global z
global x
z += 5
print (x,y,z)
Rohan()
While calling Rohan(), I am getting an error that reads "SyntaxError: name 'z' is used prior to global declaration
"
Please help me with the concepts of Global Variables and Local variables and what's causing the error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论