Font size
WorksheetsPython Lists
Total questions: 27
Worksheet time: 14mins
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"
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
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 is the output of program below?
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles[-1])
trek
cannondale
redline
specialized
a = [2, 5, 8, 1]
print("a[2]")
What is the output above?
5
8
a[2]
2
filename="example.txt"
with open(filename, "w") as myfile:
myfile.write("Pershendetje")
What happens here?
a file called 'example' is being read
a file called 'example' is created and some text is saved in it.
The text in the 'example' file is assigned to a variable
a variable called filename is created and it's value is printed on a file
What do you think is the difficulty level of Python?
Very difficult
A little difficult
Average
Not difficult
Easy
Select the one(s) which suits you.
I can write codes in python
I can create a list and let user add items to the list
I can create a text file and print some text to it
I can read some text from a file
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 is the output of the program above ?
b is bigger
a is bigger
Syntax error : tuples can't be compared
sampleSet = {"Jodi", "Eric", "Garry"}
sampleSet.add(1, "Vicki")
print(sampleSet)
{‘Vicki’, ‘Jodi’, ‘Garry’, ‘Eric’}
{‘Jodi’, ‘Vicki’, ‘Garry’, ‘Eric’}
The program executed with error
var1 = 1
var2 = 2
var3 = "3"
print(var1 + var2 + var3)
6
33
123
Error. Mixing operators between numbers and strings are not supported.
________________method removes all items from the particular dictionary.
clear( )
pop( )
del ( )
A collection of objects which ordered, immutable, and allows duplicate values.
Tuple
Sets
Module
Dictionary
A collection that is unordered, changeable, and does not allow duplicates.
Tuple
Sets
Module
Dictionary
A collection which is unordered and unindexed.
Tuple
Sets
Module
Dictionary
What will be the output?
var1=['sam', "Pam", 12,44]
var1[3]="Ram"
print(var1)
['sam', 'Pam', 12, 44]
['sam', 'Pam', 12, 'Ram']
It will give an error
['sam', 'Pam', 'Ram',44]
Which of the statements are true for the code below:
list1=["Red","Green","Yellow","Orange","Black"]
if "Red" in list1 and "Green" in list1 and "Yellow" in list1:
print("We have all the colors of traffic lights")
Print statement will be executed if the list has red/yellow/Blue
Print statement will be executed if the list has all the three colors
It will give syntax error
None of these
Which statement is correct?
List is immutable && Tuple is mutable
List is mutable && Tuple is immutable
List & Tuple are mutable
List & Tuple are immutable
Which of these about a dictionary is false?
The values of a dictionary can be accessed using keys
The keys of a dictionary can be accessed using values
Dictionaries aren't ordered
Dictionaries are mutable
