Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

2.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

3.

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

a)

hello123

b)

hello

c)

hello6

d)

Error

4.

What will be the output of the following Python code?

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

a)

2

b)

0

c)

5

d)

Error

5.

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

6.

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)

7.

Assume the following list definition:


>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']


Several short REPL sessions are shown below. Which display correct output?

a)

>>> print(a[-6])

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

IndexError: list index out of range

b)

>>> a[:] is a

True

c)

>>> print(a[4::-2])

['quux', 'baz', 'foo']

d)

>>> print(a[-5:-3])

['bar', 'baz']

e)

>>> max(a[2:4] + ['grault'])

'qux'

8.

Which of the following are true of Python lists?

a)

A list may contain any type of object except another list

b)

A given object may appear in a list more than once

c)

All elements in a list must be of the same type

d)

These represent the same list:

['a', 'b', 'c']

['c', 'a', 'b']

e)

There is no conceptual limit to the size of a list

9.

You have a list a defined as follows:


a = [1, 2, 7, 8]


Write a Python statement using slice assignment that will fill in the missing values so that a equals [1, 2, 3, 4, 5, 6, 7, 8].

a)

a[2:2] = [3, 4, 5, 6]

b)

a[1:2] = [3, 4, 5, 6]

c)

a[2:3] = [3, 4, 5, 6]

d)

a[3:5] = [3, 4, 5, 6]

10.

Tuples in Python are mutable

a)

False

b)

True

11.

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

a)

10

b)

8

c)

4

d)

6

12.

If list=[17,23,41,10] then list.append(32) will result

a)

[32,17,23,41,10]

b)

[17,23,41,10,32]

c)

[10,17,23,32,41]

d)

[41,32,23,17,10]

13.
In python the ' FLOAT data type' can be defined as...?
a)
holds alphanumerical data
b)

holds whole numbers

c)

holds a decimal point in a number

d)
hold either true or false
14.
In python the ' INTEGER data type' can be defined as...?
a)
holds alphanumeric data as text
b)
holds whole numbers
c)
holds numbers with a decimal point
d)
holds either ‘true’ or ‘false’
15.
In python the ' STRING data type' can be defined as...?
a)
holds alphanumeric text
b)
hold whole numbers
c)
holds numbers with a decimal point
d)
holds either a true or false value