Professional Documents
Culture Documents
3. What does it mean when we say that lists are ordered in Python?
A. It means that the items in a list have a defined sequence and will not change.
B. It means that the items in a list can be placed in any order.
C. It means that the items in a list are sorted alphabetically.
4. What does it mean when we say that lists are changeable in Python?
A. It means that we cannot modify the items in a list after it has been created.
B. It means that we can only modify the items at the beginning or end of the list.
C. It means that we can add, remove, or modify the items in a list after it has been created.
8. What is the result of this code: thislist = ["apple", "banana", "cherry", "apple", "cherry"]?
A. An error because of the duplicate values
B. A tuple with the values ("apple", "banana", "cherry")
C. A list with the values ["apple", "banana", "cherry", "apple", "cherry"]
9. What is the indexing in Python list and what is the index of the first item in a list?
A. Indexing refers to the arrangement of items in a list, and the index of the first item is 1.
B. Indexing refers to assigning a position number to each element in the list, and the index
of the first item is 0.
C. Indexing refers to the ability to sort a list, and the index of the first item depends on the
sorting algorithm used.
11. What happens when new items are added to a Python list?
A. The new items will replace existing items in the list
B. The new items will be placed at the end of the list
C. The new items will be placed randomly in the list
12. Is it possible to change the order of items in a list in Python?
A. No, it is not possible to change the order of items in a list in Python.
B. Yes, it is possible to change the order of items in a list in Python using certain list
methods.
C. It depends on the size of the list whether the order can be changed.
13. Which of the following statements is true about accessing elements in a list in Python?
A. You can use negative indices to access elements from the end of the list.
B. You cannot access elements in a list using their indices.
C. You can only access elements in a list using loops.
16. Which method is used to add all elements of one list to another list in Python?
A. extend()
B. insert()
C. remove()
myList = list()
listLength = int(input("Enter list length: "))
for i in range(listLength):
x = i + 1
n = int(input("Enter element %d: " % x))
myList.append(n)
if len(myList) != len(set(myList)):
print("Has duplicate?: True")
else:
print("Has duplicate?: False")
18. What is the purpose of the list() function call in the first line of the code?
A. It creates an empty list.
B. It converts a string to a list.
C. It sorts a list.
21. What is the output of this code if the user enters the following input: Enter list length: 5
and then enters the following elements for the list: 1, 2, 2, 3, 4?
A. Has duplicate?: True
B. Has duplicate?: False
C. It will throw an exception
24. Which of the following is the correct syntax to access the second element of a tuple?
A. tuple[0]
B. tuple[1]
C. tuple[-1]
26. Which of the following statements is true about tuple comprehension in Python?
A. Tuple comprehension is not supported in Python
B. Tuple comprehension syntax is similar to list comprehension syntax in Python
C. Tuple comprehension can only be used with tuples that contain numeric elements in
Python
27. Which of the following statements is true about concatenating tuples in Python?
A. Tuples cannot be concatenated in Python
B. Tuples can only be concatenated if they have the same number of elements in Python
C. Tuples can be concatenated using the "+" operator in Python
28. Which of the following statements is true about unpacking tuples in Python?
A. Only the first element of a tuple can be unpacked in Python
B. Tuples can be unpacked into multiple variables in Python
C. Unpacking tuples in Python can only be done using negative indices
29. Which of the following statements is true about iterating over a tuple in Python?
A. Tuples can be iterated over using a for loop in Python
B. Tuples can only be iterated over using a while loop in Python
C. Iterating over a tuple in Python requires converting it to a list first
30. Which method is used to get the number of items in a tuple in Python?
A. count()
B. index()
C. len()
For items 31-33, refer to the codes below:
37. Which of the following is the correct syntax to create an empty set in Python?
A. s = set()
B. s = []
C. s = ()
38. What is the result of the following code?
s1 = {1, 2, 3}
s2 = {3, 4, 5}
s3 = s1.intersection(s2)
print(s3)
A. {1, 2, 3, 4, 5}
B. {1, 2}
C. {3}
A. {1, 2, 3, 4, 5}
B. {1, 2, 3}
C. {3, 4, 5}