@@ -11,8 +11,8 @@ Programming FAQ
1111General questions
1212=================
1313
14- Is there a source code level debugger with breakpoints, single-stepping, etc. ?
15- ------------------------------------------------------------------------------
14+ Is there a source- code level debugger with breakpoints and single-stepping?
15+ ---------------------------------------------------------------------------
1616
1717Yes.
1818
@@ -208,7 +208,7 @@ Why do lambdas defined in a loop with different values all return the same resul
208208----------------------------------------------------------------------------------
209209
210210Assume you use a for loop to define a few different lambdas (or even plain
211- functions), e.g. ::
211+ functions), for example ::
212212
213213 >>> squares = []
214214 >>> for x in range(5):
@@ -227,7 +227,7 @@ they all return ``16``::
227227This happens because ``x `` is not local to the lambdas, but is defined in
228228the outer scope, and it is accessed when the lambda is called --- not when it
229229is defined. At the end of the loop, the value of ``x `` is ``4 ``, so all the
230- functions now return ``4**2 ``, i.e. ``16 ``. You can also verify this by
230+ functions now return ``4**2 ``, or ``16 ``. You can also verify this by
231231changing the value of ``x `` and see how the results of the lambdas change::
232232
233233 >>> x = 8
@@ -298,9 +298,9 @@ using multiple imports per line uses less screen space.
298298
299299It's good practice if you import modules in the following order:
300300
301- 1. standard library modules -- e.g. :mod: `sys `, :mod: `os `, :mod: `argparse `, :mod: `re `
301+ 1. standard library modules -- such as :mod: `sys `, :mod: `os `, :mod: `argparse `, :mod: `re `
3023022. third-party library modules (anything installed in Python's site-packages
303- directory) -- e.g. :mod: `!dateutil `, :mod: `!requests `, :mod: `!PIL.Image `
303+ directory) -- such as :mod: `!dateutil `, :mod: `!requests `, :mod: `!PIL.Image `
3043043. locally developed modules
305305
306306It is sometimes necessary to move imports to a function or class to avoid
@@ -494,11 +494,11 @@ new objects).
494494
495495In other words:
496496
497- * If we have a mutable object (:class: `list `, :class: `dict `, :class: `set `,
498- etc.), we can use some specific operations to mutate it and all the variables
497+ * If we have a mutable object (such as :class: `list `, :class: `dict `, :class: `set `) ,
498+ we can use some specific operations to mutate it and all the variables
499499 that refer to it will see the change.
500- * If we have an immutable object (:class: `str `, :class: `int `, :class: `tuple `,
501- etc.), all the variables that refer to it will always see the same value,
500+ * If we have an immutable object (such as :class: `str `, :class: `int `, :class: `tuple `) ,
501+ all the variables that refer to it will always see the same value,
502502 but operations that transform that value into a new value always return a new
503503 object.
504504
@@ -511,7 +511,7 @@ How do I write a function with output parameters (call by reference)?
511511
512512Remember that arguments are passed by assignment in Python. Since assignment
513513just creates references to objects, there's no alias between an argument name in
514- the caller and callee, and so no call-by-reference per se . You can achieve the
514+ the caller and callee, and so no call-by-reference as such . You can achieve the
515515desired effect in a number of ways.
516516
5175171) By returning a tuple of the results::
@@ -868,9 +868,9 @@ with either a space or parentheses.
868868How do I convert a string to a number?
869869--------------------------------------
870870
871- For integers, use the built-in :func: `int ` type constructor, e.g. ``int('144')
871+ For integers, use the built-in :func: `int ` type constructor, for example, ``int('144')
872872== 144 ``. Similarly, :func: `float ` converts to a floating-point number,
873- e.g. ``float('144') == 144.0 ``.
873+ for example, ``float('144') == 144.0 ``.
874874
875875By default, these interpret the number as decimal, so that ``int('0144') ==
876876144 `` holds true, and ``int('0x144') `` raises :exc: `ValueError `. ``int(string,
@@ -887,18 +887,18 @@ unwanted side effects. For example, someone could pass
887887directory.
888888
889889:func: `eval ` also has the effect of interpreting numbers as Python expressions,
890- so that e.g. ``eval('09') `` gives a syntax error because Python does not allow
890+ so that, for example, ``eval('09') `` gives a syntax error because Python does not allow
891891leading '0' in a decimal number (except '0').
892892
893893
894894How do I convert a number to a string?
895895--------------------------------------
896896
897- To convert, e.g., the number ``144 `` to the string ``'144' ``, use the built-in type
897+ For example, to convert the number ``144 `` to the string ``'144' ``, use the built-in type
898898constructor :func: `str `. If you want a hexadecimal or octal representation, use
899899the built-in functions :func: `hex ` or :func: `oct `. For fancy formatting, see
900- the :ref: `f-strings ` and :ref: `formatstrings ` sections,
901- e.g. ``"{:04d}".format(144) `` yields
900+ the :ref: `f-strings ` and :ref: `formatstrings ` sections.
901+ For example, ``"{:04d}".format(144) `` yields
902902``'0144' `` and ``"{:.3f}".format(1.0/3.0) `` yields ``'0.333' ``.
903903
904904
@@ -1217,7 +1217,7 @@ list, deleting duplicates as you go::
12171217 else:
12181218 last = mylist[i]
12191219
1220- If all elements of the list may be used as set keys (i.e. they are all
1220+ If all elements of the list may be used as set keys (that is, they are all
12211221:term: `hashable `) this is often faster ::
12221222
12231223 mylist = list(set(mylist))
@@ -1504,8 +1504,8 @@ How do I check if an object is an instance of a given class or of a subclass of
15041504Use the built-in function :func: `isinstance(obj, cls) <isinstance> `. You can
15051505check if an object
15061506is an instance of any of a number of classes by providing a tuple instead of a
1507- single class, e.g. ``isinstance(obj, (class1, class2, ...)) ``, and can also
1508- check whether an object is one of Python's built-in types, e.g.
1507+ single class, for example, ``isinstance(obj, (class1, class2, ...)) ``, and can also
1508+ check whether an object is one of Python's built-in types, for example,
15091509``isinstance(obj, str) `` or ``isinstance(obj, (int, float, complex)) ``.
15101510
15111511Note that :func: `isinstance ` also checks for virtual inheritance from an
@@ -1645,7 +1645,7 @@ How can I organize my code to make it easier to change the base class?
16451645
16461646You could assign the base class to an alias and derive from the alias. Then all
16471647you have to change is the value assigned to the alias. Incidentally, this trick
1648- is also handy if you want to decide dynamically (e.g. depending on availability
1648+ is also handy if you want to decide dynamically (such as depending on availability
16491649of resources) which base class to use. Example::
16501650
16511651 class Base:
@@ -1731,7 +1731,7 @@ default arguments. For example::
17311731
17321732This is not entirely equivalent, but close enough in practice.
17331733
1734- You could also try a variable-length argument list, e.g. ::
1734+ You could also try a variable-length argument list, for example ::
17351735
17361736 def __init__(self, *args):
17371737 ...
@@ -1783,7 +1783,7 @@ The :keyword:`del` statement does not necessarily call :meth:`~object.__del__` -
17831783decrements the object's reference count, and if this reaches zero
17841784:meth: `!__del__ ` is called.
17851785
1786- If your data structures contain circular links (e.g. a tree where each child has
1786+ If your data structures contain circular links (for example, a tree where each child has
17871787a parent reference and each parent has a list of children) the reference counts
17881788will never go back to zero. Once in a while Python runs an algorithm to detect
17891789such cycles, but the garbage collector might run some time after the last
@@ -2092,7 +2092,7 @@ one user but run as another, such as if you are testing with a web server.
20922092
20932093Unless the :envvar: `PYTHONDONTWRITEBYTECODE ` environment variable is set,
20942094creation of a .pyc file is automatic if you're importing a module and Python
2095- has the ability (permissions, free space, etc... ) to create a ``__pycache__ ``
2095+ has the ability (permissions, free space, and so on ) to create a ``__pycache__ ``
20962096subdirectory and write the compiled module to that subdirectory.
20972097
20982098Running Python on a top level script is not considered an import and no
0 commit comments