diff options
Diffstat (limited to 'python3.html.markdown')
-rw-r--r-- | python3.html.markdown | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/python3.html.markdown b/python3.html.markdown index 531d3b5a..b494dc1e 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -38,9 +38,11 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria # Except division which returns floats by default 35 / 5 # => 7.0 -# Truncation or Integer division +# Result of integer division truncated down both for positive and negative. 5 // 3 # => 1 -5.0 // 3.0 # => 1.0 +5.0 // 3.0 # => 1.0 # works on floats too +-5 // 3 # => -2 +-5.0 // 3.0 # => -2.0 # When you use a float, results are floats 3 * 2.0 # => 6.0 @@ -51,7 +53,6 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria # Enforce precedence with parentheses (1 + 3) * 2 # => 8 - # Boolean values are primitives True False @@ -60,7 +61,6 @@ False not True # => False not False # => True - # Equality is == 1 == 1 # => True 2 == 1 # => False @@ -79,7 +79,6 @@ not False # => True 1 < 2 < 3 # => True 2 < 3 < 2 # => False - # Strings are created with " or ' "This is a string." 'This is also a string.' @@ -471,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 @@ -557,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 @@ -572,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 |