@@ -17,6 +17,7 @@ Perhaps the most well-known statement type is the :keyword:`if` statement. For
1717example::
1818
1919 >>> x = int(input("Please enter an integer: "))
20+ Please enter an integer: 42
2021 >>> if x < 0:
2122 ... x = 0
2223 ... print('Negative changed to zero')
@@ -26,7 +27,8 @@ example::
2627 ... print('Single')
2728 ... else:
2829 ... print('More')
29- ...
30+ ...
31+ More
3032
3133There can be zero or more :keyword: `elif ` parts, and the :keyword: `else ` part is
3234optional. The keyword ':keyword: `elif `' is short for 'else if', and is useful
@@ -191,7 +193,7 @@ The :keyword:`pass` statement does nothing. It can be used when a statement is
191193required syntactically but the program requires no action. For example::
192194
193195 >>> while True:
194- ... pass # Busy-wait for keyboard interrupt
196+ ... pass # Busy-wait for keyboard interrupt (Ctrl+C)
195197 ...
196198
197199
@@ -223,14 +225,14 @@ boundary::
223225The keyword :keyword: `def ` introduces a function *definition *. It must be
224226followed by the function name and the parenthesized list of formal parameters.
225227The statements that form the body of the function start at the next line, and
226- must be indented. The first statement of the function body can optionally be a
227- string literal; this string literal is the function's documentation string, or
228- :dfn: `docstring `.
228+ must be indented.
229229
230+ The first statement of the function body can optionally be a string literal;
231+ this string literal is the function's documentation string, or :dfn: `docstring `.
232+ (More about docstrings can be found in the section :ref: `tut-docstrings `.)
230233There are tools which use docstrings to automatically produce online or printed
231234documentation, or to let the user interactively browse through code; it's good
232- practice to include docstrings in code that you write, so try to make a habit of
233- it.
235+ practice to include docstrings in code that you write, so make a habit of it.
234236
235237The *execution * of a function introduces a new symbol table used for the local
236238variables of the function. More precisely, all variable assignments in a
@@ -259,12 +261,12 @@ mechanism::
259261 >>> f(100)
260262 1 1 2 3 5 8 13 21 34 55 89
261263
262- You might object that ``fib `` is not a function but a procedure. In Python,
263- like in C, procedures are just functions that don 't return a value. In fact,
264- technically speaking, procedures do return a value, albeit a rather boring one.
265- This value is called ``None `` (it's a built-in name). Writing the value
266- `` None `` is normally suppressed by the interpreter if it would be the only value
267- written. You can see it if you really want to using :func: `print `::
264+ Coming from other languages, you might object that ``fib `` is not a function but
265+ a procedure since it doesn 't return a value. In fact, even functions without a
266+ :keyword: ` return ` statement do return a value, albeit a rather boring one. This
267+ value is called ``None `` (it's a built-in name). Writing the value `` None `` is
268+ normally suppressed by the interpreter if it would be the only value written.
269+ You can see it if you really want to using :func: `print `::
268270
269271 >>> fib(0)
270272 >>> print(fib(0))
@@ -290,7 +292,7 @@ This example, as usual, demonstrates some new Python features:
290292
291293* The :keyword: `return ` statement returns with a value from a function.
292294 :keyword: `return ` without an expression argument returns ``None ``. Falling off
293- the end of a procedure also returns ``None ``.
295+ the end of a function also returns ``None ``.
294296
295297* The statement ``result.append(b) `` calls a *method * of the list object
296298 ``result ``. A method is a function that 'belongs' to an object and is named
@@ -432,20 +434,20 @@ list. (``*name`` must occur before ``**name``.) For example, if we define a
432434function like this::
433435
434436 def cheeseshop(kind, *arguments, **keywords):
435- print("-- Do you have any", kind, '?' )
437+ print("-- Do you have any", kind, "?" )
436438 print("-- I'm sorry, we're all out of", kind)
437439 for arg in arguments: print(arg)
438- print('-'* 40)
440+ print("-" * 40)
439441 keys = sorted(keywords.keys())
440- for kw in keys: print(kw, ':' , keywords[kw])
442+ for kw in keys: print(kw, ":" , keywords[kw])
441443
442444It could be called like this::
443445
444- cheeseshop(' Limburger' , "It's very runny, sir.",
446+ cheeseshop(" Limburger" , "It's very runny, sir.",
445447 "It's really very, VERY runny, sir.",
446- client='John Cleese' ,
447- shopkeeper='Michael Palin' ,
448- sketch=' Cheese Shop Sketch' )
448+ shopkeeper="Michael Palin" ,
449+ client="John Cleese" ,
450+ sketch=" Cheese Shop Sketch" )
449451
450452and of course it would print::
451453
@@ -472,8 +474,8 @@ Arbitrary Argument Lists
472474
473475Finally, the least frequently used option is to specify that a function can be
474476called with an arbitrary number of arguments. These arguments will be wrapped
475- up in a tuple. Before the variable number of arguments, zero or more normal
476- arguments may occur. ::
477+ up in a tuple (see :ref: ` tut-tuples `) . Before the variable number of arguments,
478+ zero or more normal arguments may occur. ::
477479
478480 def write_multiple_items(file, separator, *args):
479481 file.write(separator.join(args))
@@ -644,7 +646,8 @@ extracted for you:
644646
645647* Name your classes and functions consistently; the convention is to use
646648 ``CamelCase `` for classes and ``lower_case_with_underscores `` for functions
647- and methods. Always use ``self `` as the name for the first method argument.
649+ and methods. Always use ``self `` as the name for the first method argument
650+ (see :ref: `tut-firstclasses ` for more on classes and methods).
648651
649652* Don't use fancy encodings if your code is meant to be used in international
650653 environments. Plain ASCII works best in any case.
0 commit comments