diff options
author | Sean Nam <namsangwoo1@gmail.com> | 2017-02-09 17:11:10 -0800 |
---|---|---|
committer | Sean Nam <namsangwoo1@gmail.com> | 2017-02-09 17:11:10 -0800 |
commit | 13663f3726c39639b23615b9f963ca4b30650408 (patch) | |
tree | 9b0977479e908ab0d3c4fbcb3b9cc471a557beb0 /python.html.markdown | |
parent | 5254804c1ccf51fb3c3c500a7095dd8408371837 (diff) | |
parent | 45de0120d641cfaac0bb60b25a24782ec106e719 (diff) |
Merge branch 'master' of github.com:adambard/learnxinyminutes-docs
Pulling from master to work on Java[en] inputs
Diffstat (limited to 'python.html.markdown')
-rw-r--r-- | python.html.markdown | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python.html.markdown b/python.html.markdown index bd6090c7..f8936e65 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Amin Bandali", "http://aminbandali.com"] - ["Andre Polykanine", "https://github.com/Oire"] - ["evuez", "http://github.com/evuez"] + - ["asyne", "https://github.com/justblah"] - ["habi", "http://github.com/habi"] filename: learnpython.py --- @@ -751,6 +752,24 @@ gen_to_list = list(values) print(gen_to_list) # => [-1, -2, -3, -4, -5] # Decorators +# A decorator is a higher order function, which accepts and returns a function. +# Simple usage example – add_apples decorator will add 'Apple' element into +# fruits list returned by get_fruits target function. +def add_apples(func): + def get_fruits(): + fruits = func() + fruits.append('Apple') + return fruits + return get_fruits + +@add_apples +def get_fruits(): + return ['Banana', 'Mango', 'Orange'] + +# Prints out the list of fruits with 'Apple' element in it: +# Banana, Mango, Orange, Apple +print ', '.join(get_fruits()) + # in this example beg wraps say # Beg will call say. If say_please is True then it will change the returned # message |