John Hampton added the comment: The documentation is correct. The problem that you seem to be having are due to copy and pasting in the interpreter.
The source of you first error is that after you copy >>> def scope_test(): ... def do_local(): ... spam = "local spam" ... def do_nonlocal(): ... nonlocal spam ... spam = "nonlocal spam" ... def do_global(): ... global spam ... spam = "global spam" ... into the interpreter, you press enter and the blank line tells the interpreter that you're done defining the class. However, if you look at the docs, the following statements: spam = "test spam" do_local() print("After local assignment:", spam) do_nonlocal() print("After nonlocal assignment:", spam) do_global() print("After global assignment:", spam) are supposed to be part of the class. A similar issue exists for the issues you're experiencing with the loops. Except it's the opposite. In this case: >>> for element in [1, 2, 3]: ... print(element) ... for element in (1, 2, 3): File "<stdin>", line 3 for element in (1, 2, 3): ^ SyntaxError: invalid syntax the interpreter is expecting a blank line after the print statement to indicate that the loop is done. Since the second loop starts on the lien after "print", it thinks there is an indentation error. ---------- nosy: +pacopablo _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16607> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com