wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

review python

Total questions: 20

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following is not a valid variable name in Python?

a)

var_1

b)

_var

c)

1var

d)

var$

2.

What will be the result of the following Boolean expression in Python? (3 == 3) or (5 > 10)

a)

True

b)

False

c)

None

d)

Error

3.

What is the output of the following code? x = 3.14 and type(x)

4 lines
4.

What is the result of the following expression? 5 ** 2

a)

10

b)

25

c)

7

d)

2.5

5.

What will the following code output? my_list = [1, 2, 3], my_list.append(4), and print(my_list)

a)

[1, 2, 3, 4]

b)

[4, 1, 2, 3]

c)

[1, 2, 4]

d)

[1, 4, 2, 3]

6.

What does the following code do? person = {'name': 'John', 'age': 30} and person['age'] = 31

a)

Adds a new key-value pair to the dictionary

b)

Updates the value of the key 'age'

c)

Deletes the key 'age'

d)

Throws an error because the key 'age' already exists

7.

Which of the following operations is allowed on a tuple in Python?

a)

Changing a tuple’s value

b)

Appending an item to a tuple

c)

Concatenating two tuples

d)

Removing an item from a tuple

8.

What is the purpose of the return keyword in a Python function?

a)

To exit the function

b)

To pass values into the function

c)

To return a value from the function

d)

To define a function

9.

Which of the following is the correct way to write a file in Python?

a)

f = open('file.txt', 'r')

b)

f = open('file.txt', 'w')

c)

f = open('file.txt', 'a')

d)

Both B and C

10.

What does the regular expression pattern \w match?

a)

A word character (letters, digits, and underscores)

b)

A non-word character

c)

A whitespace character

d)

A digit

11.

Which of the following is the correct way to declare a variable in Python?

a)

var = 10

b)

int var = 10

c)

10 = var

d)

var := 10

12.

What is the result of the following Boolean expression in Python? (5 > 3) and (2 < 4)

a)

True

b)

False

c)

None

d)

Error

13.

Which of the following is a valid declaration of a string in Python?

a)

string = "Hello"

b)

string = Hello

c)

string = 'Hello'

d)

Both A and C

14.

What is the result of the following expression? 10 % 3

a)

3

b)

1

c)

0

d)

10

15.

Which of the following is the correct way to declare a list in Python?

a)

list = (1, 2, 3)

b)

list = [1, 2, 3]

c)

list = {1, 2, 3}

d)

list = "1, 2, 3"

16.

What is the correct way to access the value associated with the key 'name' in the dictionary person = {'name': 'Alice', 'age': 30} ?

a)

person['name']

b)

person[name]

c)

person.get(name)

d)

Both A and C

17.

Which of the following is an immutable data structure in Python?

a)

List

b)

Dictionary

c)

Set

d)

Tuple

18.

Which of the following is the correct way to define a function in Python?

a)

function myFunc() { }

b)

def myFunc():

c)

def myFunc() { }

d)

function: myFunc()

19.

Which of the following modes is used to open a file for reading in Python?

a)

r+

b)

w

c)

r

d)

a

20.

What does the regular expression pattern \d+ match?

a)

One or more digits

b)

One or more non-digits

c)

Exactly one digit

d)

Exactly one non-digit