[Tutor] Doubt!
emile
emile at fenx.com
Wed Oct 24 01:39:25 CEST 2012
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
More information about the Tutor
mailing list