d at davea.name
Wed Oct 24 01:58:33 CEST 2012
On 10/23/2012 07:48 PM, Alexander wrote:
> On Tue, Oct 23, 2012 at 7:24 PM, Nitin Ainani <nitinainani at 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 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
> 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: ]
> Check it out, mess around, get back to me.
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?
More information about the Tutor