Font size
WorksheetsChapter 9 - Chapter 10 Revision Question Python
Total questions: 45
Worksheet time: 1hrs 20mins
Which of the following is the correct way to define a list in Python?
list = (1, 2, 3)
list = {1, 2, 3}
list = [1, 2, 3]
list = <1, 2, 3>
What is the index of the first element in a list?
(a)
What does len([1, 2, 3, 4]) return?
(a)
Which method is used to add an item at the end of a list?
add()
insert()
append()
extend()
What will be the output of this code?
(a)
What is the output of list(range(1, 5))?
(a)
What does my_list[-1] return?
First item
Last item
Middle item
Error
What will the following code output?
(a)
What is the output of this code?
(a)
What will list1 = [1, 2] + [3, 4] result in?
(a)
What is a list in Python?
How does the append() method differ from insert()?
What is the difference between list1 = [1, 2, 3] and list2 = list1.copy()?
Write Python code to remove the value 5 from the list [2, 5, 7, 5].
Write a Python statement to create a list of squares from 1 to 5 using list comprehension.
The following code is intended to replace all even numbers in the list with 0, but it doesn't work as expected. Analyze the mistake and correct it.
Analyze the following code. Why does it print three copies of the same list?
This program aims to insert 100 between 2 and 3. Why doesn't it work?
The following code is meant to remove all occurrences of 5. But it raises an error. Why, and how can it be fixed?
The following code is intended to create a new list that contains only the odd numbers from the original list. However, the output is incorrect. Analyze and correct the mistake.
Which of the following is a correct way to create a set in Python?
set = {}
set1 = set([1, 2, 3])
set1 = (1, 2, 3)
set1 = [1, 2, 3]
What is the characteristic of a Python set?
Ordered and mutable
Unordered and mutable
Ordered and immutable
Unordered and immutable
What will be the output of the following code?
(a)
What will the output be?
(a)
Which method is used to add an element to a set?
add()
append()
insert()
extend()
Which of the following defines an empty tuple?
()
{}
[]
||
Which of the following is immutable in Python?
List
Set
Dictionary
Tuple
What is the output of this code?
(a)
What will be the output of this code?
(a)
Which of these operations is not allowed on a tuple?
Indexing
Iteration
Slicing
Assignment to an element
How do you create an empty dictionary named dict?
(a)
What does this code print?
(a)
Which method returns all the keys from a dictionary?
d.values()
d.items()
d.keys()
d.get()
What is the output?
(a)
How to correctly check if a key exists in a dictionary named dict?
(a)
The following code aims to update a set with new elements. It doesn’t work as expected. Identify and correct the issue.
You are checking for membership in a large dataset. Which data type is more efficient and why?
Analyze the error in the following code:
x, y = (1, 2, 3)
Why does the following code raise an error?
t = (1, 2, 3)
t[1] = 10
What will be the output of this code and why?
d = {'a': 1, 'a': 2}
print(d)
Write a program to create a tuple with 5 elements and print each element using a loop.
Write a program to count the frequency of each character in a string using a dictionary.
Write a program to find the common elements between two sets.
Write a program to merge two dictionaries into one.
Write a program to find the maximum and minimum values in a tuple.
