[Tutor] Unexpected Indent Error Message

Alan Thwaits basicbare at gmail.com
Fri Mar 27 15:42:49 EDT 2020


Alan, you're absolutely right. Following the function def line correctly
solved the problem.

Many thanks!

Alan

On Fri, Mar 27, 2020 at 1:33 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 27/03/2020 17:18, Alan Thwaits wrote:
> > I've aligned 'death' with the print above it (checking with VSCode to be
> > certain of the alignment), and get the following:
>
> >   File "C:/Users/Alan/Documents/Python/ex43.py", line 158
> >     return 'death'
> >     ^
> > SyntaxError: 'return' outside function
>
> Its not the death that needs to be aligned its the return.
> You should review the rulkes of indentation in Python, they really are
> critical.
>
> Essentially the indentation level determines what is inside the
> function. In this case the first line (print) sets the required indent.
> All other lines in the function must align with that. (or deeper if they
> are sub blocks)
>
> >>> class EscapePod(Scene):
> >>>
> >>>     def enter(self):
> >>>         print(dedent("""
> >>>             You rush through the ship, desperately trying to make it to
> >>>         return 'death'
> ...
> >>>         if....
> >>>         else:
> >>>             print(dedent("""...
>
> As above. Notice how all the top level lines are at the same
> indent under the function def line? That is crucial.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list