Font size
WorksheetsPython Test 25 List Tuple Dictionary
Total questions: 70
Worksheet time: 1hrs 10mins
Which of the following creates a tuple?
tuple1=("a","b")
tuple1[2]=("a","b")
tuple1=(5)*2
None of the above
Choose the correct option with respect to Python.
Both tuples and lists are immutable.
Tuples are immutable while lists are mutable.
Both tuples and lists are mutable.
Tuples are mutable while lists are immutable.
colors = ["red", "green", "burnt sienna", "blue"]
print(colors[2])
What is the output of the above python code?
'blue'
It causes a run-time error.
'burnt sienna'
'green'
colors = ["red", "green", "burnt sienna", "blue"]
Which list index would select the value 'red' from the above list?
(a)
colors = ("red", "green", "burnt sienna", "blue")
print("yellow" in colors)
What is the result of the yellow in colors expression?
ValueError: 'yellow' is not in list
4
False
True
What’s the main difference between Python lists and tuples?
Lists can hold any data type and tuples can only contain int and str objects.
Lists are immutable and tuples are mutable.
Lists are mutable and tuples are immutable.
Lists are faster and tuples are slower.
Check Your Answer »
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]
What will be the output?
tuple1=['sam', "Pam", 12,44]
print(type(tuple1))
<class 'list'>
<class 'tuple'>
What will be the output?
list1=['sam', "Pam", 12,44]
print(list1[-1])
12
sam
No such index in the list
44
What will be the output?
list1=["Red","Green","Blue","Yellow"]
list1.append("Black")
print(list1)
<class 'list'>
['Red', 'Green', 'Blue', 'Yellow', 'Black']
['Black','Red', 'Green', 'Blue', 'Yellow' ]
AttributeError: 'tuple' object has no attribute 'append'
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
What will be the output?
list1=["Red","Green","Yellow","Orange","Black","Emerald blue"]
print(max(list1))
Emerald blue
Black
Red
Yellow
list1=["Red","Green","Yellow","Orange","Black","Emerald blue"]
list1.sort()
print(list1)
["Red","Green","Yellow","Orange","Black","Emerald blue"]
Not a valid function in Python3
['Black', 'Emerald blue', 'Green', 'Orange', 'Red', 'Yellow']
None
list1 = "a", "b", "c", "d";
print(type(list1))
Syntax not correct
("a", "b", "c", "d")
<class 'tuple'>
<class 'list'>
tup1=("Red","Green","Yellow","Orange","Black")
del tup1
print(tup1)
NameError: name 'tup1' is not defined
SyntaxError: invalid syntax no keyword del
("Red","Green","Yellow","Orange","Black")
None of these
What will be the output of the “hello” +1+2+3?
hello123
hello
hello6
Error
What is “Hello”.replace(“l”, “e”)?
Heeeo
Heelo
Heleo
None
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
2
0
5
Error
What will be the output of the following Python code?
print("abcdef".find("cd"))
True
2
False
Error
What will be the output of the following Python code?
print('xyyzxxyxyy'.lstrip('xyy'))
zxxyxyy
zxxy
z
Error
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
print(t[3])
t[3] = 45
print(max(t))
print(len(t))
What will be the output of the following Python code?
>>>t=(1,2,4,3)
>>>t[1:-1]
(1, 2)
(1, 2, 4)
(2, 4)
(2, 4, 3)
What type of data is: a=[(1,1),(2,4),(3,9)]?
Array of tuples
List of tuples
Tuples of lists
Invalid type
What will be the output of the following Python code?
>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> print(c)
(4,6)
(1,2,3,4)
Error as tuples are immutable
None
What will be the output of the following Python code?
>>>nums = set([1,1,2,3,3,3,4,4])
>>>print(len(nums))
7
4
8
Error, invalid syntax for formation of set
What will be the output of the following Python code?
>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b
{4,5}
{6}
Error as unsupported operand type for set data type
Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code snippet?
for x in set('pqr'):
print(x*2)
pp
rr
pqr
pqr
ppqqrr
pqrpqr
What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
None
{ None:None, None:None, None:None}
{1:None, 2:None, 3:None}
{ }
Pick the odd one in connection with collection data type
List
Tuple
Dictionary
Loop
Let list1=[2,4,6,8,10] the print(list1[-2]) will result in
10
8
4
6
What is the use of type( ) function in python ?
To create a tuple
To know the type of an element in tuple
To know the data type of the Python object
To create a List
s=[x**2 for x in range(5)]
print(s)
[0,1,2,4,5]
[0,1,4,9,16]
[0,1,4,9,16,25]
[1,4,9,16,25]
The keys in Python dictionary is specified by
=
;
+
:
Look at the following code, what will it generate
1,2,3,4,5,6,7,8,9,10,11,12
0,1,2,3,4,5,6,7,8,9,10,11,12
1,2,3,4,5,6,7,8,9,10,11,12,13
0,1,2,3,4,5,6,7,8,9,10,11,12,13
What does the following program display?
1,2,3,4
1,2,3,4,5
counter,counter,counter,counter,counter
0,1,2,3,4,5
When do you know when you come to the end of the loop?
Its states End loop
The command End is given
The indentation stops
if you wished a loop to repeat 3 types whwt should you use?
For counter in range(0,5):
For counter in range(1.3):
For counter in range(0.3):
what is the name of the variable used in the following code?
counter
for
#
Which of the following is an acceptable variable name?
no-text
8text
no_text
no_text$
How do you define(assign) variables?
var="String"
func==Hello
var : 123
word= Hello
Which one does take you to next line?
\t
\n
/n
\\
What symbol is used in python to assign values to a variable?
:
*
=
==
Which of these would work as a piece of code?
if string="Dove"
if string=="Dove"
IF string="Dove":
if string=="Dove":
What is the end after if statements?
if
Elif
Else
While
Which of the following is a correctly-formatted comment?
*Comment
"Comment"
#comment
(comment)
A line of text that Python won't try to run as code
Integer
Comment
Strings
Input
A data type than can have one of two values: True or False
Boolean
Basic Calculation
For
While
Data type for a whole number
Float
Boolean
Integer
String
A Python data type that holds positive and negative whole numbers
String
int
str
input
The Boolean operator that returns true if EITHER of its operands are true
and
or
not
equal
Which of the following pieces of code defines a list of all the numbers from 4 to 12?
range(4,12)
range(4, 13)
range( 3,12)
range(3, 13)
// means:
two times division
integer division
exact division with floating number
Put a slash
What does symbol % do?
Integer exact division
Percentage
Division
Remainder
What does "\t " make?
Goes to next line
Horizontal space between two strings
Give a title
Add a slash
A count controlled loop will..
Repeat code until a condition is met
Repeat code a specific amount of times
Repeat code a random amount of times
None of the above
What is a Count-Controlled loop?
for loop
while loop
What will this code do?
Print Numbers 1-11
Print Numbers 1-10
Print Numbers 2-10
Print Error
What sort of loop is this?
Count Controlled
Condition Controlled
Which of these is NOT a loop in python?
for loop
while loop
nested loop
if loop
What will be the output of this code?
1,2,3,4,5,6,7,8,9,10,11,12
0,2,4,6,8,10
2,4,6,8,10,12
2,4,6,8,10
Which of these will allow me to count from 0-20 in steps of 5?
for x in range(0,20):
print(x)
while x = (0,20,5):
print(x)
for x in range(0,21,5):
print(x)
for x in range(0,21,5):
print(y)
If i want to continuously check for a correct answer, what loop would i use?
for loop
while loop
Each item in a string has an "address" or index. The first index in a Python string is what?
0
1
a
A
