Skip to content

Commit 7f0c574

Browse files
committed
Sample code to understand classes in python
1 parent f6902f9 commit 7f0c574

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sampleclass.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SAMPLE CODE TO ILLUSTRATE CLASSES IN PYTHON
2+
3+
4+
5+
class TheThing(object):
6+
def __init__(self):
7+
self.number = 0
8+
def some_function(self):
9+
print "I got called."
10+
def add_me_up(self, more):
11+
self.number += more
12+
return self.number
13+
# two different things
14+
a = TheThing()
15+
b = TheThing()
16+
a.some_function()
17+
b.some_function()
18+
print a.add_me_up(20)
19+
print a.add_me_up(20)
20+
print b.add_me_up(30)
21+
print b.add_me_up(30)
22+
print a.number
23+
print b.number

0 commit comments

Comments
 (0)