-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex40_intro.py
43 lines (31 loc) · 887 Bytes
/
ex40_intro.py
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
38
39
40
41
42
43
mystuff = {'apple': "I AM APPLES!"}
print(mystuff['apple'])
import mystuff
mystuff.apple()
print(mystuff.tangerine)
mystuff['apple'] # get apple from dict
mystuff.apple() # get apple from the module
mystuff.tangerine # same thing, it's just a variable
# classess
print('~~~' * 20)
class MyStuff(object):
def __init__(self):
self.tangerine = "And now a thousand years between."
def apple(self):
print("I AM CLASSY APPLES!")
# instantiate = create; like import for modules
# instantiate a class => what you get is called an object
print('~~~' * 5)
thing = MyStuff() # this is the instantiate operation, like calling a function
thing.apple()
print(thing.tangerine)
# -------- Getting things from Things -----------
# dict style
mystuff['apples']
# module style
mystuff.apples()
print(mystuff.tangerine)
# class style
thing = MyStuff
thing.apples()
print(thing.tangerine)