Unexpected string indexing behavior

Description

Playing with string indexing/slicing, I'm seeing some (I think) non-intuitive behavior:

This prints:

I would instead have expected:

(1) A to print empty lines for all cases with the 2nd index <= -6?

(2) B to print empty lines for all cases with the 2nd index <= -2?

So, is this intentional?

Environment

None

Activity

Show:
Jon Siwek
December 4, 2013, 7:59 AM

Looked pretty wrong to me, too. See if topic/jsiwek/string-slicing-fix is better.

Robin Sommer
December 5, 2013, 6:25 AM

yeah, looks better, but I think it's now missing another piece: with the changed semantics for the end position, how does one get "everything until the end of the string"? Python has a[5:] for that.

Jon Siwek
December 5, 2013, 7:29 AM
Edited

how does one get "everything until the end of the string"? Python has a[5:] for that.

a[5:|a|] ? I.e. a[5:] is like a[5:len(a)] in Python. Probably wouldn't be hard to add the shorthand, I can take a look.

Jon Siwek
December 5, 2013, 8:15 AM

That's in the branch now.

Merged

Assignee

Unassigned

Reporter

Robin Sommer

Labels

None

External issue ID

None

Components

Affects versions

Priority

Normal