Mostly Linux & Python syntax notes and hyperlinks.

Tuesday, November 29, 2011

python: note the non-intuitive behavior of range(start,end+1)


range(a,b) starts at a and ends at b-1

>>> for n in range(1,3):
...    print str(n)
...
1
2
>>>

You could introduce bugs in your code by not being careful of this.

No comments:

Post a Comment