CGSC 1005 Lecture Notes - Lecture 10: For Loop

80 views1 pages

Document Summary

A for loop traverses (goes through elements one by one in order) over a sequence of elements. Given a file, its elements are always the lines in that file (each line is a string) After the in" it must be a sequence (not a number ex. What is written to a file must be a string. A list is a type of data structure (a way of organizing data in a computer so that it can be used efficiently) You can also make a list with variables. Lists can also be a combination of numbers, strings, etc. To access list elements one by one, we can use a for loop. Getting the # of elements in a list. We can use the len" function to find the number of elements in the list. List elements can also be accessed by using the [ ] operator. Print( list_of_names[0] ) will print the first element in the specified list.

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