forked from noisebridge/PythonClass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmult.py
59 lines (41 loc) · 1.25 KB
/
mult.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
import functools
def multip(*args):
""" return the accumulated total of all arguments multiplied together
"""
accumulated_total = 1
for i in args:
accumulated_total *= i
return accumulated_total
my_values = range(1,4)
print("values:", my_values)
print("original:", multip(*my_values))
# lets make a partial from the original function and functools.partial
multip2 = functools.partial(multip, 2)
print("x2:", multip2(*my_values))
multip3 = functools.partial(multip, 3)
print("x3:", multip3(*my_values))
multip4 = functools.partial(multip, 4)
print("x4:", multip4(*my_values))
multip222 = functools.partial(multip, 2, 2, 2)
print("x2x2x2", multip222(*my_values))
mymultiplier = multip
print(mymultiplier(10,20))
my_function_list = list()
my_function_list.append(multip)
my_function_list.append(multip2)
my_function_list.append(multip3)
my_function_list.append(multip222)
for i in my_function_list:
print(i(1,2,3,4))
my_functions = list()
for i in range(100):
my_functions.append(functools.partial(multip, i))
for i in my_functions:
print(i(1,2,3))
print my_functions
print my_function_list
for i in my_function_list:
try:
print i.__name__
except AttributeError:
print("This object has no name!")