diff options
author | Evgeniy Ginzburg <Nad.Oby@gmail.com> | 2014-08-06 23:45:44 +0300 |
---|---|---|
committer | Evgeniy Ginzburg <Nad.Oby@gmail.com> | 2014-08-06 23:45:44 +0300 |
commit | cb3217fc35f3097c4be5b39fb36bd74b5e415f6c (patch) | |
tree | cedbb3d549ea8f810ab720b09f1c56ba6b89dc6e /python3.html.markdown | |
parent | 7bcf65278c28cffd32ef051965c2e6401563acc9 (diff) | |
parent | 4349587ac4de7bc3436f68415bcf5bdfac260e5e (diff) |
Merge https://github.com/adambard/learnxinyminutes-docs
Added two minor changes in integer division to make it clear
Diffstat (limited to 'python3.html.markdown')
-rw-r--r-- | python3.html.markdown | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/python3.html.markdown b/python3.html.markdown index dc972196..b494dc1e 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -470,7 +470,10 @@ class Human(object): # A class attribute. It is shared by all instances of this class species = "H. sapiens" - # Basic initializer + # Basic initializer, this is called when this class is instantiated. + # Note that the double leading and trailing underscores denote objects + # or attributes that are used by python but that live in user-controlled + # namespaces. You should not invent such names on your own. def __init__(self, name): # Assign the argument to the instance's name attribute self.name = name @@ -556,9 +559,11 @@ def double_numbers(iterable): # double_numbers. # Note range is a generator too. Creating a list 1-900000000 would take lot of # time to be made -_range = range(1, 900000000) +# We use a trailing underscore in variable names when we want to use a name that +# would normally collide with a python keyword +range_ = range(1, 900000000) # will double all numbers until a result >=30 found -for i in double_numbers(_range): +for i in double_numbers(range_): print(i) if i >= 30: break @@ -571,10 +576,10 @@ for i in double_numbers(_range): from functools import wraps -def beg(_say): - @wraps(_say) +def beg(target_function): + @wraps(target_function) def wrapper(*args, **kwargs): - msg, say_please = _say(*args, **kwargs) + msg, say_please = target_function(*args, **kwargs) if say_please: return "{} {}".format(msg, "Please! I am poor :(") return msg |