summaryrefslogtreecommitdiffhomepage
path: root/python3.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'python3.html.markdown')
-rw-r--r--python3.html.markdown17
1 files changed, 10 insertions, 7 deletions
diff --git a/python3.html.markdown b/python3.html.markdown
index 341f0a39..3821d84f 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -37,8 +37,6 @@ Note: This article applies to Python 3 specifically. Check out [here](http://lea
1 + 1 # => 2
8 - 1 # => 7
10 * 2 # => 20
-
-# Except division which returns floats, real numbers, by default
35 / 5 # => 7.0
# Result of integer division truncated down both for positive and negative.
@@ -47,8 +45,8 @@ Note: This article applies to Python 3 specifically. Check out [here](http://lea
-5 // 3 # => -2
-5.0 // 3.0 # => -2.0
-# When you use a float, results are floats
-3 * 2.0 # => 6.0
+# The result of division is always a float
+10.0 / 3 # => 3.3333333333333335
# Modulo operation
7 % 3 # => 1
@@ -145,13 +143,13 @@ None # => None
"etc" is None # => False
None is None # => True
-# None, 0, and empty strings/lists/dicts all evaluate to False.
+# None, 0, and empty strings/lists/dicts/tuples all evaluate to False.
# All other values are True
bool(0) # => False
bool("") # => False
bool([]) # => False
bool({}) # => False
-
+bool(()) # => False
####################################################
## 2. Variables and Collections
@@ -493,7 +491,7 @@ next(our_iterator) # => "one"
next(our_iterator) # => "two"
next(our_iterator) # => "three"
-# After the iterator has returned all of its data, it gives you a StopIterator Exception
+# After the iterator has returned all of its data, it gives you a StopIteration Exception
next(our_iterator) # Raises StopIteration
# You can grab all the elements of an iterator by calling list() on it.
@@ -761,8 +759,13 @@ if __name__ == '__main__':
print(b.say('hello'))
print(b.fly)
+# To take advantage of modularization by file you could place the classes above in their own files,
+# say, human.py and bat.py
+# to import functions from other files use the following format
# from "filename-without-extension" import "function-or-class"
+
+# superhero.py
from human import Human
from bat import Bat