wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which function opens a file for reading in Python?

a)

openFile()

b)

fileOpen()

c)

open()

d)

readFile()

2.

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

3.

Which of these is mutable?

a)

List

b)

Tuple

c)

String

d)

None of the above

4.

Which built-in function returns the absolute value?

a)

abs()

b)

fabs()

c)

absolute()

d)

all()

5.

What is the output of the following program? L1 = [1, 2, 3, 4] L2 = L1 L3 = L1.copy() L4 = L3 L1[0] = [5] print(L1, L2, L3, L4)

a)

[5, 2, 3, 4]

[5, 2, 3, 4]

[1, 2, 3, 4]

[1, 2, 3, 4]

b)

[[5], 2, 3, 4]

[[5], 2, 3, 4]

[[5], 2, 3, 4]

[1, 2, 3, 4]

c)

[5, 2, 3, 4]

[5, 2, 3, 4]

[5, 2, 3, 4]

[1, 2, 3, 4]

d)

[[5], 2, 3, 4]

[[5], 2, 3, 4]

[1, 2, 3, 4]

[1, 2, 3, 4]

6.

Which of the following character is used to give single-line comments in Python?

a)

//

b)

#

c)

!

d)

/*

7.

Which keyword is used to create an alias while importing a module in Python?

a)

as

b)

alias

c)

rename

d)

with

8.

Which of the following is not a core data type in Python programming?

a)

Tuples

b)

Lists

c)

Class

d)

Dictionary

9.

Which of these is the definition for packages in Python?

a)

A set of main modules

b)

A folder of python modules

c)

A number of files containing Python definitions and statements

d)

A set of programs making use of Python modules

10.

Which arithmetic operators cannot be used with strings in Python?

a)

*

b)

-

c)

+

d)

All of the mentioned

11.

How many except statements can a try-except block have?

a)

zero

b)

one

c)

more than one

d)

more than zero

12.

What will be the output of the following Python code?

x = 50

def func(x):

print('x is', x)

x = 2
print('Changed local x to', x)

func(x)

print('x is now', x)

a)

x is 50 Changed local x to 2 x is now 50

b)

x is 50 Changed local x to 2 x is now 2

c)

x is 50 Changed local x to 2 x is now 100

d)

None of the mentioned

13.

What will be the output of the following Python code snippet? not(10<20) and not(10>30)

a)

True

b)

False

c)

Error

d)

No output

14.

Which of the following statements create a dictionary?

a)

d = {}

b)

d = {"john":40, "peter":45}

c)

d = {40:"john", 45:"peter"}

d)

All of the mentioned

15.

What does the function re.match do?

a)

matches a pattern at the start of the string

b)

matches a pattern at any position in the string

c)

such a function does not exist

d)

none of the mentioned.

16.

What is the output of the following Python code snippet? string = "Hello, World!" print(string[3:7])

a)

"Hello"

b)

"lo, "

c)

"lo, W"

d)

"lo, World"

17.

What do we call the following \n\t

a)

Escape sequence

b)

Special Character

c)

Don't have any common term

d)

Key word

18.

How can you import a specific function from a module in Python?

a)

using the 'import' keyword followed by the function name

b)

using the 'require' keyword followed by the function name

c)

using the 'import' keyword followed by the module name and function name separated by a dot

d)

using the 'use' keyword followed by the module name and function name separated by a dot

19.

list, tuple, and range are the ___ of Data Types.

a)

Sequence Types

b)

Binary Types

c)

Boolean Types

d)

None of the mentioned above

20.

Which of the following is not an exception handling keyword in Python?

a)

try

b)

except

c)

accept

d)

finally