Page 79 -
P. 79

here is waldo








                                             Imagine the variable s is set to the string below.  Your job was to
                                             determine what each of the substrings provide.













                 s[5:9]                                   “here"
                            9 minus 5 = 4 characters


                 s[10:12]                                 “is"
                            12 minus 10 = 2 characters
                                                          “Waldo"
                 s[13:18]
                             18 minus 13 = 5 characters
                                                                             Up to, but not including.
                 In general, if you specify a substring using s[a:b], then:
                      the index of the first character       the index after the last character
                  a is                                  b is








                                                                                      The second
                                                                                   index value is
                                                                                   after the last
                                                                                   character in
                                        s[13:18]                                   the substring

                                             Even though index 18      This is even though the
                                             is mentioned in the       first index value is the start
                                             substring specification,   character of the substring.
                                             it’s not included in the
                                             extracted substring.






           44    Chapter 2
   74   75   76   77   78   79   80   81   82   83   84