ITP 115 Lecture Notes - Lecture 7: Word Game, Spamalot, Master Sergeant

63 views4 pages

Document Summary

Output p y t h o n print(foo, end= ) Index tells which position the item is in: each individual item in a sequences is automatically given an index, 1st index is zero (0, last index is number of items - 1, example. 8 letters, but last index is 7 (8-1=7) Sequences and random access: using indices, we can directly access single items from a sequence, to read a single item from a sequence, use: Strings: random access msg = spamalot print(msg[2]) print(msg[6]) a. Index out of range: only valid indices of a sequence are 0 to length-1 (python supports negative indices, which go from -1 to -(length). This isn"t common in programming, and we won"t use it. : python generates an error if you read index beyond length-1. Also called out of bounds: common mistake. If sequence has 5 items, which is the index of the last item.

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