Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A():
- x=3
- class B():
- def __init__(self):
- self.x=3
- #!/usr/bin/env python
- class A:
- x = []
- def add(self):
- self.x.append(1)
- class B:
- def __init__(self):
- self.x = []
- def add(self):
- self.x.append(1)
- x = A()
- y = A()
- x.add()
- y.add()
- print "A's x:",x.x
- x = B()
- y = B()
- x.add()
- y.add()
- print "B's x:",x.x
- >>> class A:
- ... def __init__(s):
- ... s.bla = 2
- ...
- >>>
- >>> a = A()
- >>> a.bla
- 2
- >>> class Foo():
- ... i = 3
- ... def bar(self):
- ... print 'Foo.i is', Foo.i
- ... print 'self.i is', self.i
- ...
- >>> f = Foo() # Create an instance of the Foo class
- >>> f.bar()
- Foo.i is 3
- self.i is 3
- >>> Foo.i = 5 # Change the global value of Foo.i over all instances
- >>> f.bar()
- Foo.i is 5
- self.i is 5
- >>> f.i = 3 # Override this instance's definition of i
- >>> f.bar()
- Foo.i is 5
- self.i is 3
Add Comment
Please, Sign In to add comment