4 ms·
I guess not at all. It's shadowed. But this being Python, this is a way: foo = 123 def lol(foo="bar"): print(globals()["foo"], foo) That will
by diarrhea 5y ago
I guess not at all. It's shadowed. But this being Python, this is a way:
foo = 123
def lol(foo="bar"):
print(globals()["foo"], foo)
That will output "123 bar". But it's terrible!
Your example is a SyntaxError, it doesn't even compile:
In [1]: def myfunc(foo="bar"):
...: global foo
Input In [1]
global foo
^
SyntaxError: name 'foo' is parameter and global
- amelius 5y ago> But this being Python, this is a way That's why I said nonlocal or global ;)