On 10/23/2012 07:48 PM, Alexander wrote: > On Tue, Oct 23, 2012 at 7:24 PM, Nitin Ainani <nitinain...@gmail.com> 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 >> >> emptyString = "" > #consider the string to be non-empty, that is, let's say 13 characters > long (the number you chose below) > string13 = "1234567890ABC" > print ( string13 [ 0 ] ) > >> Now if we write following statement >> >> print ( s [ 0 ] ) # it gives error > ***what error? *** > The error and your example can be used to understand indexes. > s [ 0 ] is asking for the value of a specific piece of s. > s[0] is asking for the value at index Zero of string s. > S has nothing inside of it. > >> print(s[0:]) # it does not give error > #what does it give? >> print (s[13:13]) # this too does not give error > #What is the output >> why? > And with your other two examples I suggest understanding slicing. > slice! I want the whole pie, myPie [ 0: ] #the : around an index has > a special meaning. > Try a string with text and observe the output of your questions. > aString [ : ] > aString [ : 0 ] > aStr [ 1: ] > > etc > Check it out, mess around, get back to me. > Alexander Nitin:
Or even better, stick to the original thread, with the dubious title "Doubt!" What's the point of starting a second nearly-identical thread within 10 minutes? -- DaveA _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor