summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichael Lee <michael.lee.0x2a@gmail.com>2013-07-01 06:21:03 -0700
committerMichael Lee <michael.lee.0x2a@gmail.com>2013-07-01 06:21:03 -0700
commitc74780755887d270aebf5563bcfa4449e170dab0 (patch)
treeae385cbf8b0e6bb102d3cc3e447273620e2d8c57
parentcc3dc30518605f80e2ef11751a050ebd2997bac9 (diff)
Incorporated feedback from lodin/adambard/others
Changes: - Added a few lines on using "is" to compare object identity. - Removed example about lists containing arbitrary values. - Removed example about assigning lambdas to variables. - Removed example about dictionary comprehensions. - Removed the additional explanation about 'self' - Added a clarification on modules.
-rw-r--r--python.html.markdown18
1 files changed, 7 insertions, 11 deletions
diff --git a/python.html.markdown b/python.html.markdown
index c75e90c4..9324e29b 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -98,6 +98,10 @@ None #=> None
"etc" is None #=> False
None is None #=> True
+# The 'is' operator tests for object identity. This isn't
+# very useful when dealing with primitive values, but is
+# very useful when dealing with objects.
+
# None, 0, and empty strings/lists all evaluate to False.
# All other values are True
0 == False #=> True
@@ -169,9 +173,6 @@ li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
# Examine the length with len
len(li) #=> 6
-# Note: lists can contain arbitrary values
-li2 = [1, "Hello", [[], "Hi", 5,]]
-
# Tuples are like lists but are immutable.
tup = (1, 2, 3)
tup[0] #=> 1
@@ -375,8 +376,6 @@ add_10(3) #=> 13
# There are also anonymous functions
(lambda x: x > 2)(3) #=> True
-rectangle_area = lambda a, b: a * b
-print rectangle_area(3, 4) #=> 12
# There are built-in higher order functions
map(add_10, [1,2,3]) #=> [11, 12, 13]
@@ -386,9 +385,6 @@ filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
-# You can also use dictionary comprehensions
-{i: add_10(i) for i in [1, 2, 3]} #=> {1: 11, 2: 12, 3: 13}
-
####################################################
## 5. Classes
####################################################
@@ -404,8 +400,7 @@ class Human(object):
# Assign the argument to the instance's name attribute
self.name = name
- # An instance method. All methods take self as the first argument,
- # which refers to the instance of this class
+ # An instance method. All methods take self as the first argument
def say(self, msg):
return "%s: %s" % (self.name, msg)
@@ -462,7 +457,8 @@ import math as m
math.sqrt(16) == m.sqrt(16) #=> True
# Python modules are just ordinary python files. You
-# can write your own, and import them.
+# can write your own, and import them. The name of the
+# module is the same as the name of the file.
```