Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Intermediate Python

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the purpose of the try-except block?

a)

Loop control

b)

Exception handling

c)

Function definition

d)

Variable declaration

2.

Which exception is raised when dividing by zero?

a)

ValueError

b)

TypeError

c)

ZeroDivisionError

d)

ArithmeticError

3.

What does the finally clause do?

a)

Executes only if no exception

b)

Executes only if exception occurs

c)

Always executes

d)

Never executes

4.

When does the else clause in try-except execute?

a)

Always

b)

When exception occurs

c)

When no exception occurs

d)

Never

5.

What keyword is used to raise an exception manually?

a)

throw

b)

raise

c)

error

d)

exception

6.

What does if name == "main": check?

a)

Variable name

b)

If module is run directly

c)

Function name

d)

Class name

7.

What is the purpose of the global keyword?

a)

Create global function

b)

Modify global variable

c)

Import global module

d)

Define global class

8.

What does the enumerate() function return?

a)

List of values

b)

List of indices

c)

Index-value pairs

d)

Dictionary

9.

What is list comprehension?

a)

List method

b)

Elegant way to create lists

c)

List sorting

d)

List copying

10.

What will [x*2 for x in range(5)] return?

a)

[0, 1, 2, 3, 4]

b)

[0, 2, 4, 6, 8]

c)

[2, 4, 6, 8, 10]

d)

[1, 2, 3, 4, 5]

11.

What is a virtual environment in Python?

a)

Cloud environment

b)

Isolated Python environment

c)

Testing environment

d)

Virtual machine

12.

Which command creates a virtual environment?

a)

python create env

b)

virtualenv myenv

c)

create virtualenv

d)

env create

13.

What does pip freeze do?

a)

Stops pip

b)

Lists installed packages

c)

Freezes Python version

d)

Clears cache

14.

What is a lambda function?

a)

Named function

b)

Anonymous function

c)

Built-in function

d)

Class method

15.

What will (lambda x: x**2)(5) return?

a)

5

b)

10

c)

25

d)

Error

16.

How many arguments can a lambda function have?

a)

Only one

b)

Only two

c)

Any number

d)

None

17.

What does the join() method do?

a)

Joins two strings

b)

Joins list elements into string

c)

Joins two lists

d)

Joins dictionaries

18.

What will "-".join(["a", "b", "c"]) return?

a)

"a-b-c"

b)

"abc"

c)

["a-b-c"]

d)

Error

19.

What does the format() method do?

a)

Formats numbers

b)

Formats strings with values

c)

Formats dates

d)

Formats files

20.

What will "{0} and {1}".format("A", "B") return?

a)

"0 and 1"

b)

"A and B"

c)

"{A} and {B}"

d)

Error

21.

What does the map() function do?

a)

Creates a map

b)

Applies function to all items

c)

Maps keys to values

d)

Navigates data

22.

What does the filter() function return?

a)

All elements

b)

Elements where function returns True

c)

Filtered dictionary

d)

Sorted list

23.

Where is the reduce() function imported from?

a)

Built-in

b)

functools

c)

itertools

d)

collections

24.

What will list(map(lambda x: x*2, [1, 2, 3])) return?

a)

[1, 2, 3]

b)

[2, 4, 6]

c)

[1, 4, 9]

d)

Error

25.

What does list slicing [::2] mean?

a)

Every element

b)

Every second element

c)

First two elements

d)

Last two elements

26.

What will "Python"[::-1] return?

a)

"Python"

b)

"nohtyP"

c)

"Pytho"

d)

Error

27.

Which of the following is True about tuples?

a)

Mutable

b)

Can be changed

c)

Elements can be added

d)

Immutable

28.

What will {1, 2, 3}.union({3, 4, 5}) return?

a)

{1, 2, 3}

b)

{1, 2, 3, 4, 5}

c)

{3}

d)

Error

29.

What will {1, 2, 3}.intersection({2, 3, 4}) return?

a)

{1, 2, 3, 4}

b)

{2, 3}

c)

{1, 4}

d)

Error

30.

What is the DRY principle in programming?

a)

Don't Repeat Yourself

b)

Do Review Yearly

c)

Define Run Yield

d)

Data Retrieval Yearly