CMPT-101 Lecture 11: Indexes
Document Summary
#you can find letters in a message or sequence of letters by the index. #for example, try the following in the shell: #however, e and o are also in hello, but. #will return false, as they are not next to each other. #this will return the second letter of the message. #there are two kinds of indexing in python. #there is positive indexing, which works from 0,1,2,3, etc #there is also negative indexing, which works backwards with negative numbers: -3,-2,-1. #so in "hello", the letter e would be position 1 in positive indexing. #since the count starts from 0 and the last number is not included in the slice, the output is #so if s="hello", s[1:4] will return "ell" and s[-4:-1] will return "ell". #remember: the last number is not included in the slice. #with slicing, you can omit one or both of the numbers.