wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Test 25 List Tuple Dictionary

Total questions: 70

Worksheet time: 1hrs 10mins

Name
Class
Date
1.

Which of the following creates a tuple?

a)

tuple1=("a","b")

b)

tuple1[2]=("a","b")

c)

tuple1=(5)*2

d)

None of the above

2.

Choose the correct option with respect to Python.

a)

Both tuples and lists are immutable.

b)

Tuples are immutable while lists are mutable.

c)

Both tuples and lists are mutable.

d)

Tuples are mutable while lists are immutable.

3.

colors = ["red", "green", "burnt sienna", "blue"]

print(colors[2])


What is the output of the above python code?

a)

'blue'

b)

It causes a run-time error.

c)

'burnt sienna'

d)

'green'

4.

colors = ["red", "green", "burnt sienna", "blue"]


Which list index would select the value 'red' from the above list?

(a)  

5.

colors = ("red", "green", "burnt sienna", "blue")


print("yellow" in colors)


What is the result of the yellow in colors expression?

a)

ValueError: 'yellow' is not in list

b)

4

c)

False

d)

True

6.

What’s the main difference between Python lists and tuples?

a)

Lists can hold any data type and tuples can only contain int and str objects.

b)

Lists are immutable and tuples are mutable.

c)

Lists are mutable and tuples are immutable.

d)

Lists are faster and tuples are slower.

Check Your Answer »

7.

What will be the output?

var1=['sam', "Pam", 12,44]

var1[3]="Ram"

print(var1)

a)

['sam', 'Pam', 12, 44]

b)

['sam', 'Pam', 12, 'Ram']

c)

It will give an error

d)

['sam', 'Pam', 'Ram',44]

8.

What will be the output?

tuple1=['sam', "Pam", 12,44]

print(type(tuple1))

a)

<class 'list'>

b)

<class 'tuple'>

9.

What will be the output?

list1=['sam', "Pam", 12,44]

print(list1[-1])

a)

12

b)

sam

c)

No such index in the list

d)

44

10.

What will be the output?

list1=["Red","Green","Blue","Yellow"]

list1.append("Black")

print(list1)

a)

<class 'list'>

b)

['Red', 'Green', 'Blue', 'Yellow', 'Black']

c)

['Black','Red', 'Green', 'Blue', 'Yellow' ]

d)

AttributeError: 'tuple' object has no attribute 'append'

11.

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")

a)

Print statement will be executed if the list has red/yellow/Blue

b)

Print statement will be executed if the list has all the three colors

c)

It will give syntax error

d)

None of these

12.

What will be the output?

list1=["Red","Green","Yellow","Orange","Black","Emerald blue"]


print(max(list1))

a)

Emerald blue

b)

Black

c)

Red

d)

Yellow

13.

list1=["Red","Green","Yellow","Orange","Black","Emerald blue"]

list1.sort()

print(list1)

a)

["Red","Green","Yellow","Orange","Black","Emerald blue"]

b)

Not a valid function in Python3

c)

['Black', 'Emerald blue', 'Green', 'Orange', 'Red', 'Yellow']

d)

None

14.

list1 = "a", "b", "c", "d";


print(type(list1))

a)

Syntax not correct

b)

("a", "b", "c", "d")

c)

<class 'tuple'>

d)

<class 'list'>

15.

tup1=("Red","Green","Yellow","Orange","Black")

del tup1

print(tup1)

a)

NameError: name 'tup1' is not defined

b)

SyntaxError: invalid syntax no keyword del

c)

("Red","Green","Yellow","Orange","Black")

d)

None of these

16.

What will be the output of the “hello” +1+2+3?

a)

hello123

b)

hello

c)

hello6

d)

Error

17.

What is “Hello”.replace(“l”, “e”)?

a)

Heeeo

b)

Heelo

c)

Heleo

d)

None

18.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy'))

a)

2

b)

0

c)

5

d)

Error

19.

What will be the output of the following Python code?

print("abcdef".find("cd"))

a)

True

b)

2

c)

False

d)

Error

20.

What will be the output of the following Python code?

print('xyyzxxyxyy'.lstrip('xyy'))

a)

zxxyxyy

b)

zxxy

c)

z

d)

Error

21.

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

a)

print(t[3])

b)

t[3] = 45

c)

print(max(t))

d)

print(len(t))

22.

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:-1]

a)

(1, 2)

b)

(1, 2, 4)

c)

(2, 4)

d)

(2, 4, 3)

23.

What type of data is: a=[(1,1),(2,4),(3,9)]?

a)

Array of tuples

b)

List of tuples

c)

Tuples of lists

d)

Invalid type

24.

What will be the output of the following Python code?

>>> a=(1,2)

>>> b=(3,4)

>>> c=a+b

>>> print(c)

a)

(4,6)

b)

(1,2,3,4)

c)

Error as tuples are immutable

d)

None

25.

What will be the output of the following Python code?

>>>nums = set([1,1,2,3,3,3,4,4])

>>>print(len(nums))

a)

7

b)

4

c)

8

d)

Error, invalid syntax for formation of set

26.

What will be the output of the following Python code?

>>> a={4,5,6}

>>> b={2,8,6}

>>> a-b

a)

{4,5}

b)

{6}

c)

Error as unsupported operand type for set data type

d)

Error as the duplicate item 6 is present in both sets

27.

What will be the output of the following Python code snippet?

for x in set('pqr'):

print(x*2)

a)

pp

qq

rr

b)

pqr

pqr

c)

ppqqrr

d)

pqrpqr

28.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

a.clear()

print(a)

a)

None

b)

{ None:None, None:None, None:None}

c)

{1:None, 2:None, 3:None}

d)

{ }

29.

Pick the odd one in connection with collection data type

a)

List

b)

Tuple

c)

Dictionary

d)

Loop

30.

Let list1=[2,4,6,8,10] the print(list1[-2]) will result in

a)

10

b)

8

c)

4

d)

6

31.

What is the use of type( ) function in python ?

a)

To create a tuple

b)

To know the type of an element in tuple

c)

To know the data type of the Python object

d)

To create a List

32.

s=[x**2 for x in range(5)]

print(s)

a)

[0,1,2,4,5]

b)

[0,1,4,9,16]

c)

[0,1,4,9,16,25]

d)

[1,4,9,16,25]

33.

The keys in Python dictionary is specified by

a)

=

b)

;

c)

+

d)

:

34.

Look at the following code, what will it generate

a)

1,2,3,4,5,6,7,8,9,10,11,12

b)

0,1,2,3,4,5,6,7,8,9,10,11,12

c)

1,2,3,4,5,6,7,8,9,10,11,12,13

d)

0,1,2,3,4,5,6,7,8,9,10,11,12,13

35.

What does the following program display?

a)

1,2,3,4

b)

1,2,3,4,5

c)

counter,counter,counter,counter,counter

d)

0,1,2,3,4,5

36.

When do you know when you come to the end of the loop?

a)

Its states End loop

b)

The command End is given

c)

The indentation stops

37.

if you wished a loop to repeat 3 types whwt should you use?

a)

For counter in range(0,5):

b)

For counter in range(1.3):

c)

For counter in range(0.3):

38.

what is the name of the variable used in the following code?

a)

counter

b)

print

c)

for

d)

#

39.

Which of the following is an acceptable variable name?

a)

no-text

b)

8text

c)

no_text

d)

no_text$

40.
What is the name of the environment in Python that write your programs and then test them out?
a)
Shell
b)
Window
c)
IDLE
d)
CLI
41.
What symbol do you use to make a comment in Python?
a)
@
b)
¬
c)
;
d)
#
42.
What type of loop is used when you know how many times you want to repeat something?
a)
A WHILE Loop
b)
An IF function
c)
A FOR Loop
d)
A Variable
43.

How do you define(assign) variables?

a)

var="String"

b)

func==Hello

c)

var : 123

d)

word= Hello

44.

Which one does take you to next line?

a)

\t

b)

\n

c)

/n

d)

\\

45.

What symbol is used in python to assign values to a variable?

a)

:

b)

*

c)

=

d)

==

46.

Which of these would work as a piece of code?

a)

if string="Dove"

b)

if string=="Dove"

c)

IF string="Dove":

d)

if string=="Dove":

47.

What is the end after if statements?

a)

if

b)

Elif

c)

Else

d)

While

48.

Which of the following is a correctly-formatted comment?

a)

*Comment

b)

"Comment"

c)

#comment

d)

(comment)

49.

A line of text that Python won't try to run as code

a)

Integer

b)

Comment

c)

Strings

d)

Input

50.

A data type than can have one of two values: True or False

a)

Boolean

b)

Basic Calculation

c)

For

d)

While

51.

Data type for a whole number

a)

Float

b)

Boolean

c)

Integer

d)

String

52.

A Python data type that holds positive and negative whole numbers

a)

String

b)

int

c)

str

d)

input

53.

The Boolean operator that returns true if EITHER of its operands are true

a)

and

b)

or

c)

not

d)

equal

54.

Which of the following pieces of code defines a list of all the numbers from 4 to 12?

a)

range(4,12)

b)

range(4, 13)

c)

range( 3,12)

d)

range(3, 13)

55.

// means:

a)

two times division

b)

integer division

c)

exact division with floating number

d)

Put a slash

56.

What does symbol % do?

a)

Integer exact division

b)

Percentage

c)

Division

d)

Remainder

57.

What does "\t " make?

a)

Goes to next line

b)

Horizontal space between two strings

c)

Give a title

d)

Add a slash

58.

A count controlled loop will..

a)

Repeat code until a condition is met

b)

Repeat code a specific amount of times

c)

Repeat code a random amount of times

d)

None of the above

59.

What is a Count-Controlled loop?

a)

for loop

b)

while loop

60.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

61.

What sort of loop is this?

a)

Count Controlled

b)

Condition Controlled

62.

Which of these is NOT a loop in python?

a)

for loop

b)

while loop

c)

nested loop

d)

if loop

63.

What will be the output of this code?

a)

1,2,3,4,5,6,7,8,9,10,11,12

b)

0,2,4,6,8,10

c)

2,4,6,8,10,12

d)

2,4,6,8,10

64.

Which of these will allow me to count from 0-20 in steps of 5?

a)

for x in range(0,20):

print(x)

b)

while x = (0,20,5):

print(x)

c)

for x in range(0,21,5):

print(x)

d)

for x in range(0,21,5):

print(y)

65.

If i want to continuously check for a correct answer, what loop would i use?

a)

for loop

b)

while loop

66.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
67.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
68.

Each item in a string has an "address" or index. The first index in a Python string is what?

a)

0

b)

1

c)

a

d)

A

69.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
70.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17