CSC108H5 Lecture Notes - Lecture 6: Carbonara

144 views4 pages
Verified Note
17 Oct 2018
School
Course
Professor

Document Summary

Colors=[(cid:862)red(cid:863), (cid:862)ora(cid:374)ge(cid:863), (cid:862)(cid:455)ello(cid:449)(cid:863), (cid:862)gree(cid:374)(cid:863), (cid:862)i(cid:374)digo(cid:863), (cid:862)(cid:449)hite(cid:863): since this is and indexed list the first item in list has zero as its index, accessing items on the list created above: >>>print(colors[0]) red: printing color name of third color from the list: Indigo: to see how many colors are on the list, we use len() function: 6: to see the name of colors on the list we give command: [(cid:862)red(cid:863), (cid:862)ora(cid:374)ge(cid:863), (cid:862)(cid:455)ello(cid:449)(cid:863), (cid:862)gree(cid:374)(cid:863), (cid:862)i(cid:374)digo(cid:863), (cid:862)(cid:449)hite(cid:863): for removing item(s) from list we use remove() method: We see that (cid:374)o(cid:449) (cid:449)e ha(cid:448)e a(cid:374) updated list (cid:449)ithout the (cid:272)olor (cid:862)(cid:449)hite(cid:863: we add item(s) to the list using the append command: If we want to insert item(s) between two already existing items in the list we use insert() method with the syntax: List. insert(index,obj: here, parameters are: index and object. Index: refers to the position where the new item is to be located: object: refers to the item to be inserted.

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