Font size
WorksheetsPython Lists Quiz 1
Total questions: 80
Worksheet time: 40mins
Which of the following operations can be performed on lists in Python?
Concatenation, repetition, membership, slicing
Traversing a list using loops
Built-in functions like len(), append(), and remove()
All of the above
What does the `len()` function do when applied to a list in Python?
It removes an element from the list
It returns the length of the list
It sorts the list in ascending order
It appends an element to the list
Which method is used to add an element to the end of a list in Python?
append()
insert()
extend()
pop()
What is the purpose of the `pop()` method in Python lists?
To add an element to the list
To remove and return the last element of the list
To count the number of occurrences of an element in the list
To reverse the order of the list
Which of the following methods can be used to sort a list in Python?
reverse()
sorted()
sort()
Both B and C
What is the difference between `sort()` and `sorted()` in Python?
`sort()` returns a new list, while `sorted()` modifies the original list
`sort()` modifies the original list, while `sorted()` returns a new list
Both modify the original list
Both return a new list
Which method is used to count the frequency of an element in a list?
count()
index()
remove()
sum()
What is the purpose of the `index()` method in Python lists?
To find the position of an element in the list
To remove an element from the list
To add an element to the list
To reverse the order of the list
Which of the following is NOT a built-in method for Python lists?
append()
extend()
multiply()
insert()
What is the result of the operation `list1 + list2` in Python?
It concatenates list1 and list2
It multiplies the elements of list1 and list2
It removes duplicates from list1 and list2
It reverses the order of list1 and list2
Which of the following operations can be used to traverse a list in Python?
Using a for loop
Using a while loop
Using list comprehension
All of the above
What is the purpose of slicing in Python lists?
To remove elements from the list
To access a subset of elements from the list
To sort the list
To reverse the list
Which method is used to reverse the order of elements in a Python list?
reverse()
sort()
append()
pop()
What is a nested list in Python?
A list that contains only numeric values
A list that contains another list as an element
A list that is sorted in ascending order
A list that is empty
Which of the following programs can be implemented using Python lists?
Finding the maximum value in a list
Finding the mean of numeric values in a list
Counting the frequency of elements in a list
All of the above
What is the result of the operation `list1 * 3` in Python?
It multiplies all elements of list1 by 3
It repeats the elements of list1 three times
It removes duplicates from list1
It reverses the order of list1
Which method is used to add multiple elements to a list in Python?
append()
extend()
insert()
pop()
What is the purpose of the `min()` function in Python lists?
To find the smallest element in the list
To find the largest element in the list
To calculate the sum of all elements in the list
To count the number of elements in the list
Which of the following is a valid way to find the mean of numeric values in a Python list?
Using the sum() function and dividing by the length of the list
Using the max() function
Using the min() function
Using the reverse() function
What is the purpose of a linear search on a list in Python?
To find the maximum value in the list
To find the minimum value in the list
To search for an element in the list sequentially
To sort the list in ascending order
Which method is used to remove an element from a specific position in a Python list?
remove()
pop()
insert()
index()
What is the result of the operation `list1[1:4]` in Python?
It returns the first four elements of list1
It returns elements from index 1 to index 4 (excluding index 4)
It removes elements from index 1 to index 4
It reverses the order of elements from index 1 to index 4
Which method is used to insert an element at a specific position in a Python list?
append()
insert()
extend()
pop()
Which of the following is a valid way to check if an element exists in a Python list?
Using the `in` keyword
Using the `not` keyword
Using the `append()` method
Using the `remove()` method
What is the result of the operation `list1.remove(3)` in Python?
It removes the element at index 3
It removes the first occurrence of the value 3 in the list
It removes all occurrences of the value 3 in the list
It removes the last element of the list
Which of the following is a valid way to find the maximum value in a Python list?
Using the max() function
Using the min() function
Using the sum() function
Using the reverse() function
What is the purpose of the `remove()` method in Python lists?
To remove the last element of the list
To remove the first occurrence of a specified value from the list
To remove all elements from the list
To remove elements from a specific index
Which of the following operations can be used to find the frequency of elements in a Python list?
Using the count() method
Using a for loop
Using a linear search
All of the above
What is the result of the operation `list1[-1]` in Python?
It returns the first element of the list
It returns the last element of the list
It removes the last element of the list
It returns the length of the list
Which of the following is a valid way to find the sum of numeric values in a Python list?
Using the sum() function
Using the max() function
Using the min() function
Using the reverse() function
What is the result of the operation `list1.append(5)` in Python?
It returns the last element of list1
It sorts the list1 in ascending order
It removes the element 5 from list1
It adds the element 5 to the end of list1
Which method is used to remove all elements from a Python list?
delete()
pop()
remove()
clear()
What does the `sorted()` function do when applied to a list in Python?
It sorts the list in place and returns None
It reverses the order of the list
It sorts the list in ascending order and returns a new list
It removes duplicates from the list
Which method is used to remove the first occurrence of a specific element from a Python list?
delete()
clear()
remove()
pop()
What does the `count()` method do in Python lists?
Counts the number of unique elements in the list
Counts the number of even elements in the list
Counts the total number of elements in the list
Counts the number of occurrences of a specific element
Which of the following is a valid way to concatenate two lists in Python?
Using the extend() method
Both A and C
Using the + operator
Using the append() method
What is the result of the operation `list1 + list2` in Python?
It slices list1
It concatenates list1 and list2
It checks membership of list2 in list1
It repeats list1
How can you check if an element is a member of a list in Python?
Using the `in` keyword
Using the `find()` method
Using the `membership()` function
Using the `exists()` method
What does the operation `list1 * 3` do in Python?
It slices list1 into three parts
It repeats the elements of list1 three times
It concatenates list1 three times
It checks if 3 is a member of list1
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
Which of these codes is correct for creating a list of numbers?
num = ('10','29','37','109')
num = ['10','29','37','109']
num == ('10','29','37','109')
num = ['10 29 37 109']
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
variable.sort() will do what?
Sort the list into alphabetical order
Sort the list into reverse order
Create a new list
Error
What does the '#' allow you to do?
Repeat code
Comment on code
Print code
End code
An empty list can be declared as
fruitList = ""
fruitList = ["empty"]
fruitList == []
fruitList = []
Each item in a list has an "address" or index. The first index in a Python list is what?
1
0
a
A
In programming, lists are often known as...
Arrays
Elements
Indexes
Data
What is the output of the following?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
[‘ab’, ‘cd’].
[‘AB’, ‘CD’].
None of the above
[None, None]
Which of the following commands will create a list?
a) list1 = list()
b) list1 = [].
c) list1 = list([1, 2, 3])
d) all of the mentioned
list1 = list()
list1 = [].
list1 = list([1, 2, 3])
all of the mentioned
Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?
3
5
1
25
Suppose list1 is [1, 5, 9], what is sum(list1) ?
1
9
15
none
What will be the output?
names1 = ['Amir', 'Bala', 'Chales']
if 'amir' in names1:
print(1)
else: print(2)
None
1
2
error
Which of the following is the correct way to add the number 4 to mylist?
mylist + 4
mylist.append(4)
mylist.append([4])
4.append(mylist)
Which of the following commands will return the length of the list mylist?
length(mylist)
len(mylist)
mylist.length()
mylist.len()
Which would be the correct code to access number 10
list_2d[3][4]
list_2d= [2,3]
list_2d[2][3]
list_2d(0,0)
A two-dimensional array Array_2d consists of data: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]. What is the output of print(Array_2d[1][1])?
1
2
5
6
An empty list can be declared as
fruitList = ""
fruitList = ["empty"]
fruitList == []
fruitList = []
Write the output of the following code :
L=[“Amit”,”Sumit”,”Naina”]
L1=[“Sunil”]
print(L + L1)
a. [‘Amit’ , ‘Sumit’ , ‘Naina’ , [‘Sunil’]]
b. [‘Amit’ , ‘Sumit’ , ‘Naina’ , ‘Sunil’]
c. List can not concatenate
d. None of the above
Result of list slice is also a list?(T/F)
a. True
b. False
What is the output of the code above
AA-B-CBA-B-CC
A-B-CAA-B-CBA-B-C
AA-B-CBA-B-CC
AA-B-CBA-B-CCA-B-C
What is the output of the code above
10
20
30
40
Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
What will be the output of the following Python statement?
>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
If a=(1,2,3,4), a[1:-1] is _________
a) Error, tuple slicing doesn’t exist
b) [2,3]
c) (2,3,4)
d) (2,3)
What is the result of the following operation in Python: 'del my_list[2]'?
It deletes the third element from 'my_list'
It deletes the second element from 'my_list'
It clears the entire list 'my_list'
It appends the number 2 to 'my_list'
What is the output of this code snippet?
(a)
What is the output of this code snippet?
(a)
How can you extract every second element from a list using slicing?
list[1::2]
list[::2]
list[2:]
list[::3]
What happens if you try to slice a list with an out-of-range index?
Slicing a list with an out-of-range index returns the last element of the list.
Slicing a list with an out-of-range index returns the original list.
Slicing a list with an out-of-range index returns an empty list.
Slicing a list with an out-of-range index raises an IndexError.
veggies = ['carrot', 'broccoli', 'potato', 'asparagus'] veggies.insert(veggies.index('broccoli'), 'celery') print(veggies)
[‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’]
[‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]
[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]
[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]
To insert 5 to the third position in list1, we use which command?
list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
0
1
4
2
What is the output when we execute list(“hello”)?
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
[‘hello’]
[‘hello’]
None of the Above
Which list comprehension creates a list of even numbers from 1 to 10?
[x for x in range(1, 11) if x % 2 == 0]
[x for x in range(1, 11) if x % 2 != 0]
[x for x in range(2, 11, 2)]
[x * 2 for x in range(1, 6)]
What's the output of this conditional list comprehension? [x if x < 3 else 10 for x in range(5)]
[0, 1, 2, 3, 4]
[0, 1, 2, 10, 10]
[10, 10, 10, 3, 4]
[0, 1, 2, None, None]
