CSC108H1 Lecture Notes - Lecture 6: Memory Address
12 views3 pages
yifanyang and 39659 others unlocked
21
CSC108H1 Full Course Notes
Verified Note
21 documents
Document Summary
Lists can contain items of any type, including other lists. >>> grades = [["assignment 1", 80], ["assignment 2", 90], To access a nested item, first select the sublist, and then treat the result as a regular list. For example, to access "assignment 1", we can first get the sublist and then use it as we would a regular list: Both sublist and grades[0] contain the memory address of the ["assignment 1", We can access the items inside the nested lists like this: The bodies of loops can contain any statements, including other loops. When this occurs, this is known as a nested loop. Here is a nested loop involving 2 for loops: for i in range(10, 13): for j in range(1, 5): print(i, j) Notice that when i is 10, the inner loop executes in its entirety, and only after j has ranged from. 1 through 4 is i assigned the value 11.