<html><body bgcolor="#FFFFFF"><div>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.</div><div><br></div><div>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.</div><div>Hope that helps</div><div>-luke&nbsp;<br><br>Sent from my iPhone</div><div><br>On Aug 9, 2010, at 11:02 AM, Daniel &lt;.asterix@gmail.com&gt; wrote:<br><br></div><div></div><blockquote type="cite"><div>Hi, I'm trying to solve an exercise, a beginners one but I have a question. So the exercise sounds like this:<br><br>Define a string s = ’colorless’. Write a Python statement that changes this to ’colour-<br>less’, using only the slice and concatenation operations.<br>
<br>So I did wrote this:<br><pre><font size="4"><b><font size="4"><span class="n">1)s</span> <span class="o">=</span> <span class="s">'colorless'</span><br><span class="n">2)ss</span> <span class="o">=</span> <span class="n">s</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s">'u'</span> <span class="o">+</span> <span class="n">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:]</span><br>
<span class="k">3)print</span><span class="p">(</span><span class="n">ss</span><span class="p">)<br><br></span></font></b><font size="4"><span class="p">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<br>
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<br>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<br>
confusing. <br></span></font><b><font size="4"><span class="p"></span></font><br></b></font></pre>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Tutor maillist &nbsp;- &nbsp;<a href="mailto:Tutor@python.org"><a href="mailto:Tutor@python.org">Tutor@python.org</a></a></span><br><span>To unsubscribe or change subscription options:</span><br><span><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a></span><br></div></blockquote></body></html>