CMPT-101 Lecture 11: Indexes

69 views1 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents