ITP 115 Lecture Notes - Lecture 6: Reserved Word, Random Access, Sequential Access

56 views3 pages

Document Summary

For loop repeats code, but not based on a condition. For loop repeats its loop body for each element of the sequence, in order. Instead, it repeats based on a sequence: when it reaches the end of the sequence, the loop ends. Follow with a new variable (variable will only be used for this loop) Follow w/the sequence you want to loop through for variable in sequence: Sequence is an ordered set of things . A group of items stored together in a collection. Examples in python: a range of numbers (e. g. 1, 2, 3 or 2, 4, 6 etc. , string variables (e. g. hello start with h, then e, l, l, o, lists, tuples. Create sequences with range() range() function will generate a sequence based on some parameters (aka arguments) range(int stop) Up to but not including stop range(6) 0, 1, 2, 3, 4, 5. Returns sequence range(int start, int stop, int step)

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