Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add(a, b):
- #some code
- def subtract(a, b):
- #some code
- operations = [add, subtract]
- operations[0]( 5,3)
- operations[1](5,3)
- def the_simple_way(a, b):
- # blah blah
- def the_complicated_way(a, b):
- # blah blah
- def foo(way):
- if way == 'complicated':
- doit = the_complicated_way
- else:
- doit = the_simple_way
- doit(a, b)
- def do_add(a, b):
- return a+b
- def do_sub(a, b):
- return a-b
- handlers = {
- 'add': do_add,
- 'sub': do_sub,
- }
- print handlers[op](a, b)
- o = MyObject()
- f = o.method
- f(1, 2) # same as o.method(1, 2)
Add Comment
Please, Sign In to add comment