Why do I get an invalid syntax when defining a global variable?

末鹿安然 提交于 2021-02-04 08:39:05

问题


def pLatin_converter (self):
    movetoend = ""
    index = 0
    global pig = ""

I'm getting an 'invalid syntax' on the global pig = "" line and I don't understand why.


回答1:


The global variable can't be assigned a value in the global statement.

Split the two:

global pig
pig=""


来源:https://stackoverflow.com/questions/49279682/why-do-i-get-an-invalid-syntax-when-defining-a-global-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!