TECHSMART PYTHON UNIT 4 REVIEW QUESTIONS
AND VERIFIED ANSWERS
What is the length of the list below?
my_list = [2, 4, 8, 16, 32, 64, 128, 256] - ANSWER 8
Length is the number of values in a list.
In the list below, what value is at index position 0?
my_list = [2, 4, 8, 16, 32, 64, 128, 256] - ANSWER 2
List indexes start counting at 0, so 0 is the position of the first item in the list.
In the list below, what is the index position of the value 256?
my_list = [2, 4, 8, 16, 32, 64, 128, 256] - ANSWER 7
List indexes start counting at 0, so the final item in a list has an index equal to
the list's length - 1.
What is the value at index position 2?
test = [93, 95, 87, 79, 97, 89] - ANSWER 87
Index is the order of an item in a list. The count starts from the front of the list
at 0.
When the append function adds a new item to a list, where does it put the item?
- ANSWER At the end of the list.
Append means to add on to the end. It puts the new item at the end of the list.
, In the code below, which line of code replaces the last item in the list with a
new value.
groceries = ["cheese", "OJ", "peanut butter", "milk"]
healthy = "low-fat milk"
first = groceries[0]
groceries[3] = healthy - ANSWER groceries[3] = healthy
Bracket notation [ ] gets a specific position in a list. Use it to get an item at that
position, or to replace an item at that position.
What is the index position of the value "The Yellow Balloon"?
books = ["The Hunger Games", "The Gray Bird", "The Cat in the Hat", "One
Fish, Two Fish", "The Yellow Balloon"] - ANSWER 4
Because list indexes start counting at 0, the index of the final item is always the
length of the list - 1.
How could you change the following code to use the len() function to get the
length of book_length?
books = ["The Hunger Games", "The Gray Bird", "The Cat in the Hat", "One
Fish, Two Fish", "The Yellow Balloon"]
book_length = 5 - ANSWER book_length = len(books)
The len() function returns the length of the collection that is passed to it as an
argument
Which of the following is an example of a list?
(0, 1, 2, 3, 4, 5)
[0, 1, 2, 3, 4, 5] - ANSWER [0, 1, 2, 3, 4, 5]
Lists must be surrounded by square brackets
What data type does the operator return? - ANSWER boolean
what does append mean? - ANSWER The append() method in python adds a
single item to the existing list.
AND VERIFIED ANSWERS
What is the length of the list below?
my_list = [2, 4, 8, 16, 32, 64, 128, 256] - ANSWER 8
Length is the number of values in a list.
In the list below, what value is at index position 0?
my_list = [2, 4, 8, 16, 32, 64, 128, 256] - ANSWER 2
List indexes start counting at 0, so 0 is the position of the first item in the list.
In the list below, what is the index position of the value 256?
my_list = [2, 4, 8, 16, 32, 64, 128, 256] - ANSWER 7
List indexes start counting at 0, so the final item in a list has an index equal to
the list's length - 1.
What is the value at index position 2?
test = [93, 95, 87, 79, 97, 89] - ANSWER 87
Index is the order of an item in a list. The count starts from the front of the list
at 0.
When the append function adds a new item to a list, where does it put the item?
- ANSWER At the end of the list.
Append means to add on to the end. It puts the new item at the end of the list.
, In the code below, which line of code replaces the last item in the list with a
new value.
groceries = ["cheese", "OJ", "peanut butter", "milk"]
healthy = "low-fat milk"
first = groceries[0]
groceries[3] = healthy - ANSWER groceries[3] = healthy
Bracket notation [ ] gets a specific position in a list. Use it to get an item at that
position, or to replace an item at that position.
What is the index position of the value "The Yellow Balloon"?
books = ["The Hunger Games", "The Gray Bird", "The Cat in the Hat", "One
Fish, Two Fish", "The Yellow Balloon"] - ANSWER 4
Because list indexes start counting at 0, the index of the final item is always the
length of the list - 1.
How could you change the following code to use the len() function to get the
length of book_length?
books = ["The Hunger Games", "The Gray Bird", "The Cat in the Hat", "One
Fish, Two Fish", "The Yellow Balloon"]
book_length = 5 - ANSWER book_length = len(books)
The len() function returns the length of the collection that is passed to it as an
argument
Which of the following is an example of a list?
(0, 1, 2, 3, 4, 5)
[0, 1, 2, 3, 4, 5] - ANSWER [0, 1, 2, 3, 4, 5]
Lists must be surrounded by square brackets
What data type does the operator return? - ANSWER boolean
what does append mean? - ANSWER The append() method in python adds a
single item to the existing list.