[Tutor] Question about strings

Luke Paireepinart rabidpoobear at gmail.com
Mon Aug 9 18:15:42 CEST 2010


Hey email in plain text in the future, HTML is not kind to mobile screens and in general you should plaintext reply to tech lists.

All list indices start from 0. But you don't get the last value. So slice[1:5] would skip the first char and then include the next 3. It's the same as range. Range(1,100) returns 1,2,....,99.
Hope that helps
-luke 

Sent from my iPhone

On Aug 9, 2010, at 11:02 AM, Daniel <.asterix at gmail.com> wrote:

> Hi, I'm trying to solve an exercise, a beginners one but I have a question. So the exercise sounds like this:
> 
> Define a string s = ’colorless’. Write a Python statement that changes this to ’colour-
> less’, using only the slice and concatenation operations.
> 
> So I did wrote this:
> 1)s = 'colorless'
> 2)ss = s[:4] + 'u' + s[4:]
> 
> 3)print(ss)
> 
> I do not understand something. So on the second line, the slicing lasts from the start of the s string to the forth character. But from were
> 
> does the counting start? 0 or 1? From this code it's obvious that it starts from one, but how, strings counting doesn't start from 0? If I do
> len(s) i get 9 but if I do s[9] I get an error, out of range. Can please someone clear me this indexing thing? It's so frustrating and
> 
> confusing. 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100809/374d816e/attachment.html>


More information about the Tutor mailing list