[Tutor] still breaking chains

Danny Yoo danny.yoo at gmail.com
Mon Apr 13 01:05:02 CEST 2015


On Apr 12, 2015 4:00 PM, "Jim Mooney" <cybervigilante at gmail.com> wrote:
>
> If join returns a string, why am I getting a syntax error when I try  to
> slice it?
>
> >>> 'alfabeta'[2:5]
> 'fab'
> >>> ''.join(['a', 'l', 'f', 'a', 'b', 'e', 't', 'a')[2:5]
> SyntaxError: invalid syntax

If you're seeing a SyntaxError, don't look for explanations that are
semantic.  Look for syntax.

In this case, note that the list of characters had not been closed with a
right bracket yet.

Best of wishes!


More information about the Tutor mailing list