Font size
WorksheetsPython 2A
Total questions: 80
Worksheet time: 41mins
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
I have no idea
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]
What would this out put? print(users[0][0])
smith
ben
sam
james
The list needs one more name added to the end - "Marina". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Marina)
append(nameList,"Marina")
nameList.append["Marina",7]
nameList.append("Marina")
nameList.append("Marina", "Marina", "Marina", "Marina", "Marina", "Marina")
What would this out put? print(users[2][1])
error
16
brown
smith
something
Which of the following methods is used to add an element to the end of a list in Python?
`insert()`
`append()`
`extend()`
`add()`
What will be the output of the following code snippet? ```python my_list = [1, 2, 3] my_list.insert(1, 4) print(my_list) ```
`[1, 4, 2, 3]`
`[1, 2, 3, 4]`
`[4, 1, 2, 3]`
`[1, 2, 4, 3]`
Which of the following operations will remove all elements from a set in Python?
`set.clear()`
`set.remove()`
`set.discard()`
`set.delete()`
What is the result of the following set operation? ```python set1 = {1, 2, 3} set2 = {3, 4, 5} result = set1.union(set2) ```
`{1, 2, 3, 4, 5}`
`{3}`
`{1, 2, 3}`
`{4, 5}`
Which of the following data types is immutable in Python?
List
Set
Tuple
Dictionary
What is the result of the following code? ```python my_set = {1, 2, 3} my_set.add(2) print(my_set) ```
`{1, 2, 3, 2}`
`{1, 2, 3}`
`{1, 3}`
`{2, 3}`
Which of the following is a mutable data type in Python?
String
Tuple
List
Integer
How can you create a set with the elements 1, 2, and 3 in Python?
`set = {1, 2, 3}`
`set = [1, 2, 3]`
`set = (1, 2, 3)`
`set = {1: 2, 3}`
What will be the output of the following code? ```python my_tuple = (1, 2, 3) my_tuple[0] = 4 ```
`(4, 2, 3)`
`(1, 2, 3)`
`TypeError`
`(4, 1, 2, 3)`
What is the primary characteristic that differentiates a list from a set in Python?
Lists are ordered and sets are unordered
Lists are immutable and sets are mutable
Lists do not allow duplicates and sets do
Lists use key-value pairs and sets do not
Which data structure would be most suitable for storing a collection of unique tags for a blog post?
List
Set
Tuple
Dictionary
Which of the following data structures allows for the storage of duplicate items?
Set
Dictionary
Tuple
All of the above
What would be the output of the following code? tags = {'python', 'coding', 'tutorial', 'python'}
{'python', 'coding', 'tutorial', 'python'}
{'python', 'coding', 'tutorial'}
What is the main benefit of using a set over a list in Python?
Given the coordinates (10.0, 20.0), which data structure is most appropriate for storing them?
List
Set
Tuple
Dictionary
What will happen if you try to change an item in a tuple?
The item will be changed
An error will be raised
The item will be removed
The tuple will convert to a list
Which of the following is a correct example of a list in Python?
to_do = ('buy groceries', 'write report', 'call mum')
to_do = ['buy groceries', 'write report', 'call mum']
to_do = {'buy groceries', 'write report', 'call mum'}
to_do = {'buy groceries': 1, 'write report': 2, 'call mum': 3}
If you need a collection of items that must remain in the order you add them, which data structure would you use?
Set
Dictionary
List
All of the above
Can a list contain elements of different data types?
No
Yes
Only if they are immutable
Only if they are mutable
What kind of data structure is best suited for representing RGB colour values?
List
Set
Tuple
Dictionary
Which data structure is most appropriate for storing a list of attendees where each attendee should only be listed once?
List
Set
Tuple
Dictionary
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"]
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
Consider this list, what will be the highest index the list can have:
li=[1,2,3,4,5]
2
3
4
5
The count() method returns the number of times the specified element appears in the list.
What is the output of this code?
3
2
1
0
Output of this code?
[2,4,6,8,10]
['2','4','6','8','10']
[0,2,4,6,8]
[10,8,6,4,2]
What is the output of this code?
X
Y
Error
Which of the following function is used to count the number of elements in a list ?
count( )
find( )
len( )
index( )
mylist = ["a","b"]
mylist[1] = "c"'
print(mylist)
["a","c"]
["a","b"]
["a","b","c"]
mylist
What would the output of the program be?
thisList = ["square", "circle", "triangle", "octagon"]
if "triangle" in thisList:
print("Yes, 'triangle' is in the list")
else:
print("No triangle here!")
Yes, 'triangle' is in the list
"No triangle here!"
In a list called "players" if you wanted to delete the item with an index of 3 which of the following examples of code would be correct?
players.pop[3]
players.delete(3)
players.remove(3)
players.pop(3)
What will line 3 OUTPUT?
3
2
TRUE
FALSE
list1 = ["hello", "hey", "hi"]
print(list1)
How many items will be printed?
1
2
3
0
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
What will be the output of the following Python code? *
x={1,3,5}
y={2,4,6}
x+y
{1,3,5,2,4}
{1,3,5,2,4,6}
Error as the duplicate item 6 is present in both sets
Error as unsupported operand type(s) for +: 'set' and 'set'
Which of the following functions will return the symmetric difference between two sets, x and y? *
x | y
x ^ y
x & y
x – y
What will be the output of the following Python code?
x = {6,5}
y = {2,3,5,6}
x<y
{1,2}
True
False
Invalid operation
The _________ function removes the first element of a set and the last element of a list.
remove
pop
discard
dispose
If x={5,6,7,8}, which of the following statements is false?
print(len(x))
print(min(x))
x.remove(5)
x[2]=45
One of the following functions is not used with Python String
Split
Remove
Replace
Choose the correct syntax of the split function:
x.split[]
split(x)
x.split(",", 3)
X.SPLIT(",", 3)
Choose the correct syntax of the replace function:
x.Replace(x)
x.replace(y)
x.replace(3,x)
x.replace("j","3")
Choose the correct code to print line of 10 stars using repetition operation:
print("**********")
print("*"*10)
print("*"^10)
print("*"+10)
The correct syntax for converting the string x to uppercase is :
X.upper()
upper(x)
x.UPPER[ ]
x.upper()
The correct syntax for converting the string myname to lowercase is :
myNAME.lower[ ]
myname.lower( )
myname.upper( )
myname_lower(12 )
To remove the spaces present at start and end of the string, you can use
split()
len()
strip()
remove()
Let x= "Python", the output of print(x.upper()) is
python
PYTHON
_PYTHON
"PYTHON"
Let x= "python is a high level language", the output of print(x[5].replace("n","*")) is
pytho* is a high level language
python is a high level language
*
Error
Let x= "python is a high level language", the output of print(len(x[-1])) is
1
31
Error
25
Let x= "Python is a high level language", the output of print(x.replace(x[-3],"3")) is
Error
Python is 3 high level l3ngu3ge
Python is a high l3v3l languag3
Python is a high level language
Let x= "Python is a high level language", the output of print(x[7].upper()) is
Python is a high level language
PYTHON IS A HIGH LEVEL LANGUAGE
I
S
Let x= "Python is a high level language", the output of print(x[2].upper()+x[3].lower()+x[-1]) is
THE
The
ThE
the
Let x= "Python is a high level language", the output of print(x[-4].upper()+x[8]+x[-1]) is
Use
Age
USE
Error
Let x= "Python is a high level language", the output of
print(x.split("i", 2))
['Pyth', 'n is a high level language']
['Python is ', ' high level l', 'nguage']
['Python ', 's a h', 'gh level language']
Error
Let x= "Python", the output of
print(x[0])
print(x[1])
print(x[2])
PYT
P
y
t
T
h
o
n
oh
Let x= "Python", the output of
print(x[0])
print(x[-1])
print(x[-2])
P
N
O
p
O
n
t
h
y
P
n
o
How to create a single element tuple
(1,)
(1)
{1}
[1]
tuple([1])
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
What is the output of the code above
(1, '2', 3, 4, 5)
syntax error
(1, 2, 3, 4, 5)
('1', '2', '3', '4', '5')
Which of the following is true
a is assigned a value of 1
b is assigned a value of [2,3]
b is assigned a value of (2,3)
b is assigned a value of 2
What is the output of the program above ?
b is bigger
a is bigger
Syntax error : tuples can't be compared
What is the output of the program above ?
True
False
Which function is used to return the count of a specific element in a tuple?
D. count()
C. index()
B. min()
A. max()
How can a tuple be indirectly modified in Python?
C. Using tuple unpacking
A. Using the del statement
D. Using the remove() method
B. Using the append() method
What is the result of the expression: (10,20,30)[1]?
D. Error
C. 30
B. 20
A. 10
What is the result of the expression: (10,20,30,40,50,60,70,80,90)[2:7:2]?
A. (30, 40, 50)
B. (30, 50, 70)
D. (30, 40, 60)
C. (30, 50, 90)
Which function is used to return the maximum value from a tuple in Python?
D. find_max()
C. maximum_value()
B. max()
A. maximum()
What will be the output of below Python code?
tuple1=(5,1,7,6,2)
tuple1.pop(2)
print(tuple1)
(5,1,6,2)
(5,1,7,6)
(5,1,7,6,2)
Error
What will be the output of below Python code?
tuple1=(2,4,3)
tuple3=tuple1*2
print(tuple3)
(4,8,6)
(2,4,3,2,4,3)
(2,2,4,4,3,3)
Error
What will be the output of below Python code?
tupl=([2,3],"abc",0,9)
tupl[0][1]=1
print(tupl)
([2,3],"abc",0,9)
([1,3],"abc",0,9)
([2,1],"abc",0,9)
Error
Find the output of the given Python program?
t = (5,4,3,2,1)
x = sum(t,2)
print(x)
15
17
30
Error
