forked from zedshaw/learn-python3-thw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex40a.py
68 lines (43 loc) · 1.01 KB
/
ex40a.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
### @export "part0"
mystuff = {'apple': "I AM APPLES!"}
print(mystuff['apple'])
### @export "part1"
# this goes in mystuff.py
def apple():
print("I AM APPLES!")
### @export "part2"
import mystuff
mystuff.apple()
### @export "part3"
def apple():
print("I AM APPLES!")
# this is just a variable
tangerine = "Living reflection of a dream"
### @export "part4"
import mystuff
mystuff.apple()
print(mystuff.tangerine)
### @export "part5"
mystuff['apple'] # get apple from dict
mystuff.apple() # get apple from the module
mystuff.tangerine # same thing, it's just a variable
### @export "part6"
class MyStuff(object):
def __init__(self):
self.tangerine = "And now a thousand years between"
def apple(self):
print("I AM CLASSY APPLES!")
### @export "part7"
thing = MyStuff()
thing.apple()
print(thing.tangerine)
### @export "part8"
# dict style
mystuff['apples']
# module style
mystuff.apples()
print(mystuff.tangerine)
# class style
thing = MyStuff()
thing.apples()
print(thing.tangerine)