Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bar:
- def __init__(self, x):
- self.x = x
- barob = Bar(6)
- def foobar():
- barob = Bar(3) #local scope, the barob in global namespace is not affected.
- foobar()
- print(barob.x) #prints 6
- def foobar2():
- global barob #barob is the one in global space
- barob = Bar(3)
- foobar2()
- print(barob.x) #prints 3
- barob = Bar(5)
- def foobar3():
- barob.x = 7
- foobar3()
- print(barob.x) #prints 7. Why?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement