<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><blockquote type="cite"><div><p> for range(1,1): means
executing once to me.</p></div></blockquote><div>The indexing/slicing approach was designed for indexing and slicing. Then it made sense to have range() match. But range() is not part of the for construction. It is a convenience function for providing an iterable of integers. And you are welcome to write your own range-like iterable if you want.</div><div><br></div><div>But if you want to look once, you'd use range(1), not range(1,2) anyway. Clear as day.</div><div><br></div><div>And if you use: range(n, n+I), it is very clear that you will loop i times.</div><div><br></div><blockquote type="cite">
<div><font face="monospace, monospace">s[:n] + s[n:] == s //
doesn't work. I don't think it should work though<br></font></div></blockquote><div><br></div><div>Have you ever used a 1-based and closed-end indexing language that supported slicing? I have (matlab), and these kinds of constructions are really ugly and prone to error. It's not that you want to be able to divide a sequence and immediately put it back together, it's that you often want to do one thing with the first part of a sequence, and another with the second part, and you don't want them to overlap.</div><br><blockquote type="cite"><div><font face="monospace, monospace">
</font></div>
<div><font face="monospace, monospace">len(s[:n]) == n //
works<br>
</font></div>
<div><font face="monospace, monospace">len(s[:-n]) == n //
rather independent but would still work if language is otherwise
unchanged.<br>
</font></div>
<div><font face="monospace, monospace">len(s[n:i]) == i - n //
doesn't work. Does it need to?<br></font></div></blockquote><div><br></div><div>It's not that it HAS to - it's that it's much less likely that you will make off by one errors if it does.</div><br><div>-CHB</div></body></html>