I was working with scope in python
a = 10
{
a = 33
}
and I got this error,
File "", line 3 a= 33 ^ SyntaxError: invalid syntax
so it means block scope is only for functions in python?
I was working with scope in python
a = 10
{
a = 33
}
and I got this error,
File "", line 3 a= 33 ^ SyntaxError: invalid syntax
so it means block scope is only for functions in python?
def foo():
a = 33
print(f"Inside: {a}") # Inside: 33
a = 10
foo()
print(f"Outside: {a}") # Outside: 10
I think this example of function scope is the only way to get something like block scope in Python. Idea taken from OP and confirmed in Block scope in Python