mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue #23921: Standardized documentation whitespace formatting.
Original patch by James Edwards.
This commit is contained in:
parent
387235085c
commit
dba903993a
63 changed files with 445 additions and 409 deletions
|
|
@ -207,7 +207,7 @@ functions), e.g.::
|
|||
|
||||
>>> squares = []
|
||||
>>> for x in range(5):
|
||||
... squares.append(lambda: x**2)
|
||||
... squares.append(lambda: x**2)
|
||||
|
||||
This gives you a list that contains 5 lambdas that calculate ``x**2``. You
|
||||
might 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``::
|
|||
|
||||
>>> squares = []
|
||||
>>> for x in range(5):
|
||||
... squares.append(lambda n=x: n**2)
|
||||
... squares.append(lambda n=x: n**2)
|
||||
|
||||
Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed
|
||||
when 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.
|
|||
args['a'] = 'new-value' # args is a mutable dictionary
|
||||
args['b'] = args['b'] + 1 # change it in-place
|
||||
|
||||
args = {'a':' old-value', 'b': 99}
|
||||
args = {'a': 'old-value', 'b': 99}
|
||||
func3(args)
|
||||
print(args['a'], args['b'])
|
||||
|
||||
|
|
@ -655,16 +655,15 @@ Essentially, assignment always binds a name to a value; The same is true of
|
|||
``def`` and ``class`` statements, but in that case the value is a
|
||||
callable. Consider the following code::
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
B = A
|
||||
|
||||
a = B()
|
||||
b = a
|
||||
print(b)
|
||||
>>> class A:
|
||||
... pass
|
||||
...
|
||||
>>> B = A
|
||||
>>> a = B()
|
||||
>>> b = a
|
||||
>>> print(b)
|
||||
<__main__.A object at 0x16D07CC>
|
||||
print(a)
|
||||
>>> print(a)
|
||||
<__main__.A object at 0x16D07CC>
|
||||
|
||||
Arguably the class has a name: even though it is bound to two names and invoked
|
||||
|
|
@ -1099,7 +1098,7 @@ How do I iterate over a sequence in reverse order?
|
|||
Use the :func:`reversed` built-in function, which is new in Python 2.4::
|
||||
|
||||
for x in reversed(sequence):
|
||||
... # do something with x...
|
||||
... # do something with x ...
|
||||
|
||||
This won't touch your original sequence, but build a new copy with reversed
|
||||
order to iterate over.
|
||||
|
|
@ -1107,7 +1106,7 @@ order to iterate over.
|
|||
With Python 2.3, you can use an extended slice syntax::
|
||||
|
||||
for x in sequence[::-1]:
|
||||
... # do something with x...
|
||||
... # do something with x ...
|
||||
|
||||
|
||||
How 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
|
|||
definition::
|
||||
|
||||
class C:
|
||||
def meth (self, arg):
|
||||
def meth(self, arg):
|
||||
return arg * 2 + self.attribute
|
||||
|
||||
|
||||
|
|
@ -1438,9 +1437,9 @@ that does something::
|
|||
|
||||
def search(obj):
|
||||
if isinstance(obj, Mailbox):
|
||||
# ... code to search a mailbox
|
||||
... # code to search a mailbox
|
||||
elif isinstance(obj, Document):
|
||||
# ... code to search a document
|
||||
... # code to search a document
|
||||
elif ...
|
||||
|
||||
A better approach is to define a ``search()`` method on all the classes and just
|
||||
|
|
@ -1448,11 +1447,11 @@ call it::
|
|||
|
||||
class Mailbox:
|
||||
def search(self):
|
||||
# ... code to search a mailbox
|
||||
... # code to search a mailbox
|
||||
|
||||
class Document:
|
||||
def search(self):
|
||||
# ... code to search a document
|
||||
... # code to search a document
|
||||
|
||||
obj.search()
|
||||
|
||||
|
|
@ -1509,7 +1508,7 @@ How do I call a method defined in a base class from a derived class that overrid
|
|||
Use the built-in :func:`super` function::
|
||||
|
||||
class Derived(Base):
|
||||
def meth (self):
|
||||
def meth(self):
|
||||
super(Derived, self).meth()
|
||||
|
||||
For version prior to 3.0, you may be using classic classes: For a class
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue