On 10/23/2012 04:14 PM, Nitin Ainani wrote:
Dear Sir/Madam,

I am  new to python I have a question. It is as follows:

Suppose *s* is a variable and *s* stores empty string

s=""
Now if we write following statement


print(s[0])      # it gives error


print(s[0:])    # it does not give error

why?

See http://docs.python.org/tutorial/introduction.html and in particular section 3.1.2 on Strings where you'll find

"Degenerate slice indices are handled gracefully: an index that is too large is replaced by the string size, an upper bound smaller than the lower bound returns an empty string."

HTH,

Emile

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to