Question: PYTHON MULTI CHOICE QUESTIONS 1a) What is the value of names after the following code segment has run? names = [] names.append(Amy) names.append(Bob) names.append(Peg) names[0]
PYTHON MULTI CHOICE QUESTIONS
1a) What is the value of names after the following code segment has run?
names = [] names.append("Amy") names.append("Bob") names.append("Peg") names[0] = "Cy" names.insert(0, "Ravi") ['Ravi', 'Cy', 'Amy', 'Bob', 'Peg'] |
['Cy', 'Amy', 'Bob', 'Peg'] |
['Ravi', 'Cy', 'Bob', 'Peg'] |
['Ravi', 'Amy', 'Bob', 'Peg'] |
1b) What is the value of the variable indexValue after the following code snippet runs?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"] indexValue = states.index("Pennsylvania") 1c) Which statement(s) allows us to initialize the list numbers with 10 elements all set to zero?
numbers = [0] |
numbers[10] = 0 |
numbers = [0] * 10 |
numbers[10] = [0] * 10 |
1d) What is the resulting content of the list letters after this code snippet?
letters = list("abcdefg") | letters contains a list with the contents: ["a", "b", "c", "d", "e", "f", "g"] |
| letters contains a list with the contents: ["abcdefg"] |
| Invalid Type Error |
| letters contains a list with the contents: ("abcdefg") |
1e) Which of the following code segments will result in values containing the list ["Hydrogen", "Helium", "Lithium"]?
values = [] values.append("Lithium") values.append("Helium") values.append("Hydrogen") |
values = [] values.append("Hydrogen") values.append("Helium") values.append("Lithium") |
values = ["Hydrogen"] values.append("Helium", "Lithium") |
values = [] values.append(["Hydrogen", "Helium", "Lithium"]) |
1f) Lists are mutable. The elements of a list might be immutable types (like int, string, float).
-True
-False
1g) A list is a heterogeneous compound type, allowing elements of mixed types to be part of the same list object.
-True
-False
1h) Assume the following statement appears in a program:
mylist = []
Which of the following statements would you use to add the string 'Labrador' to the list at index 0?
-mylist[0] = 'Labrador' |
-mylist.insert(0, 'Labrador') |
-mylist.append('Labrador') |
-mylist.insert('Labrador', 0) |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
