Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Case 1
- x=1
- def func():
- x=5
- print(x)
- func()
- 5
- #Case 2
- x=1
- def func():
- print(x) #First print statement
- x=5
- print(x) #Second print statement
- func()
- UnboundLocalError: local variable 'x' referenced before assignment
- def func():
- x=5
- print(x)
- def func():
- print(x) #First print statement
- x=5
- print(x) #Second print statement
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement