CSE 1010 Lecture Notes - Lecture 8: For Loop

26 views2 pages
Verified Note

Document Summary

Cse1010 - lecture 8 - for loops & ranges. For loops: used for iterating over a sequence. With the for loop you can execute a set of statements, once for each item in the sequence. For loop format: for variable in collection: body. The for loop automatically increments, as opposed to while loops. Therefore, for loops don"t require an indexing variable to be set beforehand. Example: nums = [10, 20, 30, 40] #list for n in nums: print(n) # takes each number out of nums and puts it in n. For loops can also iterate over strings since they contain a sequence of characters. The range function: to loop through a set of code a specific number of times we can use the range function. The range returns a sequence of numbers, starting from 0 by default, and increments by 1 by default as well, until it ends at a specified number.

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

Related Questions