Search code examples
pythonpython-3.xglobal-variables

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


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.


Solution

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

    Split the two:

    global pig
    pig = ""