forked from zedshaw/learn-python3-thw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex42_demo.py
More file actions
38 lines (26 loc) · 682 Bytes
/
ex42_demo.py
File metadata and controls
38 lines (26 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class TheThing(object):
def __init__(self):
self.number = 0
def some_function(self):
print("I got called.")
def add_me_up(self, more):
self.number += more
return self.number
# two different things
a = TheThing()
b = TheThing()
a.some_function()
b.some_function()
print(a.add_me_up(20))
print(b.add_me_up(30))
print(a.number)
print(b.number)
# Study this. This is how you pass a variable
# from one class to another. You will need this.
class TheMultiplier(object):
def __init__(self, base):
self.base = base
def do_it(self, m):
return m * self.base
x = TheMultiplier(a.number)
print(x.do_it(b.number))