summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-06-06 17:50:05 (GMT)
committerGeorg Brandl <georg@python.org>2009-06-06 17:50:05 (GMT)
commit4c324b9801dfd7939820ffb3ba50583300f2ceeb (patch)
treede0ef6bbe1c173bb6ca8015bae8bdf53923ef3dc /Doc
parent9be5998760bb4a8d013a4d1e6daa9c3cc8d57586 (diff)
downloadcpython-4c324b9801dfd7939820ffb3ba50583300f2ceeb.zip
cpython-4c324b9801dfd7939820ffb3ba50583300f2ceeb.tar.gz
cpython-4c324b9801dfd7939820ffb3ba50583300f2ceeb.tar.bz2
#6211: elaborate a bit on ways to call the function.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/tutorial/controlflow.rst19
1 files changed, 14 insertions, 5 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index cc1d334..3c6d164 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -312,14 +312,23 @@ defined to allow. For example::
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
while True:
ok = raw_input(prompt)
- if ok in ('y', 'ye', 'yes'): return True
- if ok in ('n', 'no', 'nop', 'nope'): return False
+ if ok in ('y', 'ye', 'yes'):
+ return True
+ if ok in ('n', 'no', 'nop', 'nope'):
+ return False
retries = retries - 1
- if retries < 0: raise IOError('refusenik user')
+ if retries < 0:
+ raise IOError('refusenik user')
print complaint
-This function can be called either like this: ``ask_ok('Do you really want to
-quit?')`` or like this: ``ask_ok('OK to overwrite the file?', 2)``.
+This function can be called in several ways:
+
+* giving only the mandatory argument:
+ ``ask_ok('Do you really want to quit?')``
+* giving one of the optional arguments:
+ ``ask_ok('OK to overwrite the file?', 2)``
+* or even giving all arguments:
+ ``ask_ok('OK to overwrite the file?', 2, 'Come on, only yes or no!')``
This example also introduces the :keyword:`in` keyword. This tests whether or
not a sequence contains a certain value.