CSC 1200 Lecture : python notes cmsc 201 (11)

10 views4 pages
2 Apr 2023
School
Course
Professor

Document Summary

You can loop through the list items by using a for loop: Print all items in the list, one by one: thislist = ["apple", "banana", "cherry"] for x in thislist: print(x) Learn more about for loops in our python for loops chapter. You can also loop through the list items by referring to their index number. Use the range() and len() functions to create a suitable iterable. Print all items by referring to their index number: thislist = ["apple", "banana", "cherry"] for i in range(len(thislist)): print(thislist[i]) The iterable created in the example above is [0, 1, 2]. You can loop through the list items by using a while loop. Use the len() function to determine the length of the list, then start at 0 and loop your way through the list items by referring to their indexes. Remember to increase the index by 1 after each iteration.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions