3 odpowiedzi
+ 3
"global" isn't used to declare a global variable, but to use a global variable in a function. To declare a global variable, just declare it in the global scope (outside of all functions and classes)
a = 5 # global variable
def f():
a = 7 # local variable, doesn't affect global a
def g():
global a
a = 7 # changes global variable
+ 2
They both throw a syntax error.
EDIT: You changed the original question.
It throws an error because its syntax doesn't allow to have variable assignment.
https://docs.python.org/3/reference/simple_stmts.html#global
+ 1
White spases are not allowed,Python is dynamically typed, means that you don't have to declare what type each variable is ,The variable is always assigned with the equal sign, followed by the value of the variable.There are some reserved word s for Python and can not be used as variable name. The correct is a = 10