Syntax of global and nonlocal keywords

Instead of this syntax:

global x
x = 2

nonlocal y
y = 3

what do you think if Python would allow writing directly

global x = 2
nonlocal y = 3

?

And in an expression:

3*(global x)

to specify that x refers to a global variable?

2 Likes

As global is not used at the place the variable is defined it is use where it will be accessed.
Using a syntax that makes it look like a declaration seems to be potentially misleading.

3 Likes