@@ -207,7 +207,7 @@ functions), e.g.::
207207
208208 >>> squares = []
209209 >>> for x in range(5):
210- ... squares.append(lambda: x**2)
210+ ... squares.append(lambda: x**2)
211211
212212This gives you a list that contains 5 lambdas that calculate ``x**2 ``. You
213213might expect that, when called, they would return, respectively, ``0 ``, ``1 ``,
@@ -234,7 +234,7 @@ lambdas, so that they don't rely on the value of the global ``x``::
234234
235235 >>> squares = []
236236 >>> for x in range(5):
237- ... squares.append(lambda n=x: n**2)
237+ ... squares.append(lambda n=x: n**2)
238238
239239Here, ``n=x `` creates a new variable ``n `` local to the lambda and computed
240240when the lambda is defined so that it has the same value that ``x `` had at
@@ -539,7 +539,7 @@ desired effect in a number of ways.
539539 args['a'] = 'new-value' # args is a mutable dictionary
540540 args['b'] = args['b'] + 1 # change it in-place
541541
542- args = {'a':' old-value', 'b': 99}
542+ args = {'a': ' old-value', 'b': 99}
543543 func3(args)
544544 print(args['a'], args['b'])
545545
@@ -655,16 +655,15 @@ Essentially, assignment always binds a name to a value; The same is true of
655655``def `` and ``class `` statements, but in that case the value is a
656656callable. Consider the following code::
657657
658- class A:
659- pass
660-
661- B = A
662-
663- a = B()
664- b = a
665- print(b)
658+ >>> class A:
659+ ... pass
660+ ...
661+ >>> B = A
662+ >>> a = B()
663+ >>> b = a
664+ >>> print(b)
666665 <__main__.A object at 0x16D07CC>
667- print(a)
666+ >>> print(a)
668667 <__main__.A object at 0x16D07CC>
669668
670669Arguably the class has a name: even though it is bound to two names and invoked
@@ -1099,15 +1098,15 @@ How do I iterate over a sequence in reverse order?
10991098Use the :func: `reversed ` built-in function, which is new in Python 2.4::
11001099
11011100 for x in reversed(sequence):
1102- ... # do something with x...
1101+ ... # do something with x ...
11031102
11041103This won't touch your original sequence, but build a new copy with reversed
11051104order to iterate over.
11061105
11071106With Python 2.3, you can use an extended slice syntax::
11081107
11091108 for x in sequence[::-1]:
1110- ... # do something with x...
1109+ ... # do something with x ...
11111110
11121111
11131112How do you remove duplicates from a list?
@@ -1405,7 +1404,7 @@ A method is a function on some object ``x`` that you normally call as
14051404definition::
14061405
14071406 class C:
1408- def meth (self, arg):
1407+ def meth(self, arg):
14091408 return arg * 2 + self.attribute
14101409
14111410
@@ -1438,21 +1437,21 @@ that does something::
14381437
14391438 def search(obj):
14401439 if isinstance(obj, Mailbox):
1441- # ... code to search a mailbox
1440+ ... # code to search a mailbox
14421441 elif isinstance(obj, Document):
1443- # ... code to search a document
1442+ ... # code to search a document
14441443 elif ...
14451444
14461445A better approach is to define a ``search() `` method on all the classes and just
14471446call it::
14481447
14491448 class Mailbox:
14501449 def search(self):
1451- # ... code to search a mailbox
1450+ ... # code to search a mailbox
14521451
14531452 class Document:
14541453 def search(self):
1455- # ... code to search a document
1454+ ... # code to search a document
14561455
14571456 obj.search()
14581457
@@ -1509,7 +1508,7 @@ How do I call a method defined in a base class from a derived class that overrid
15091508Use the built-in :func: `super ` function::
15101509
15111510 class Derived(Base):
1512- def meth (self):
1511+ def meth(self):
15131512 super(Derived, self).meth()
15141513
15151514For version prior to 3.0, you may be using classic classes: For a class
0 commit comments