CSC 1200 Lecture Notes - Blackcurrant

8 views4 pages
2 Apr 2023
School
Course
Professor

Document Summary

To change the value of a specific item, refer to the index number: Change the second item: thislist = ["apple", "banana", "cherry"] thislist[1] = "blackcurrant" print(thislist) To change the value of items within a specific range, define a list with the new values, and refer to the range of index numbers where you want to insert the new values: Change the values "banana" and "cherry" with the values "blackcurrant" and. "watermelon": thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"] thislist[1:3] = ["blackcurrant", "watermelon"] print(thislist) If you insert more items than you replace, the new items will be inserted where you specified, and the remaining items will move accordingly: Change the second value by replacing it with two new values: thislist = ["apple", "banana", "cherry"] thislist[1:2] = ["blackcurrant", "watermelon"] print(thislist) Note: the length of the list will change when the number of items inserted does not match the number of items replaced.

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