Chapter 4 - Self-Test Questions
Which one of the following is NOT a common operation on lists? a. access b. replace c. interleave d. append e. insert f. delete
c
Lists and tuples must each contain at least one element. True/False
False
For fruit = 'strawberry', what does the following for loop output? for k in range(0, len(fruit), 2): print(k) a. srwer b. tabry
a
For lst = [4, 2, 9, 1], what is the result of the following operation, lst.insert(2, 3)? a. [4, 2, 3, 9, 1] b. [4, 3, 2, 9, 1] c. [4, 2, 9, 2, 1]
a
What would be the range of index values for a list of 10 elements? a. 0-9 b. 0-10 c. 1-10
a
Which of the following set of operations can be applied to any sequence type? a. len(s), s[i], s + w (concatenation) b. max(s), s[i], sum(s) c. len(s), s[i], s.sort()
a
For nums = [10, 30, 20, 40], what does the following for loop output? for k in nums: print(k) a. [10, 20, 30, 40] b. [10, 30, 20, 40] c. [10, 30, 20]
b
For nums = [10, 30, 20, 40], what does the following for loop output? for k in range(1, 4): print(k) a. [10, 30, 20] b. [30, 20, 40] c. [10, 30, 20, 40]
b
For nums = [12, 4, 11, 23, 18, 41, 27], what is the value of k when the while loop terminates? k = 0 while k < len(nums) and nums[k] != 18: k = k + 1 a. 3 b. 4 c. 5
b
Which of the following is true? a. Lists and tuples are denoted by the use of square brackets. b. Lists are denoted by the use of square brackets and tuples are denoted by the use of parentheses. c. Lists are denoted by the use of parentheses and tuples are denoted by square brackets.
b
Which of the following sequences is a mutable type? a. strings b. lists c. tuples
b
Which of the following would be the resulting list after inserting the value 50 at index 2? original = [35, 15, 45, 28] a. [35, 50, 15, 45, 28] b. [35, 15, 50, 45, 28] c. [50, 35, 15, 45, 28]
b
Which of the following is the correct way to denote a tuple of one element? a. [6] b. (6) c. [6,] d. (6,)
d