Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active July 27, 2020 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaming/86c83bb6a12e1a9729a8431dc57c5350 to your computer and use it in GitHub Desktop.
Save weaming/86c83bb6a12e1a9729a8431dc57c5350 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
class C:
a = 1
def __init__(self):
self.a += 1
def update(self):
self.a += 1
print(C.a)
c = C()
print(c.a)
c.update()
print(c.a)
print('---')
print(C.a)
c = C()
print(c.a)
c.update()
print(c.a)
print('---' * 2)
class C:
a = []
def __init__(self):
self.a.append(1)
def update(self):
self.a.append(1)
print(C.a)
c = C()
print(c.a)
c.update()
print(c.a)
print('---')
print(C.a)
c = C()
print(c.a)
c.update()
print(c.a)
print('---' * 2)
class C:
a = []
def __init__(self):
self.a = []
self.a.append(1)
def update(self):
self.a.append(1)
print(C.a)
c = C()
print(c.a)
c.update()
print(c.a)
print('---')
print(C.a)
c = C()
print(c.a)
c.update()
print(c.a)
'''
> python3 x.py
1
2
3
---
1
2
3
------
[]
[1]
[1, 1]
---
[1, 1]
[1, 1, 1]
[1, 1, 1, 1]
------
[]
[1]
[1, 1]
---
[]
[1]
[1, 1]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment