wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming-Quizz

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

What is the main difference between a list and a tuple in Python?

a)

Lists are immutable; tuples are mutable

b)

Lists are mutable; tuples are immutable

c)

Lists can contain numbers only; tuples can contain strings only

d)

Lists are slower than tuples

2.

What will be the output of the following code?

x = 10 y = 3 print(x // y, x % y)

a)

3 1

b)

3 0

c)

3.33 1

d)

3 3

3.

How do you create a lambda function to calculate the square of a number n?

a)

square = lambda n: n + n

b)

square = lambda n: n * n

c)

square(n) = n ** 2

d)

def square(n): return n * n

4.

Which Python function is used to read a file line by line?

a)

read()

b)

readline()

c)

write()

d)

openfile()

5.

How do you extract "Python" from the string "I love Python programming" using slicing?

a)

s[7:13]

b)

s[7:12]

c)

s[8:13]

d)

s[7:14]

6.

Which regex pattern matches exactly 3 digits anywhere in a string?

a)

\d{2}

b)

\d{3}

c)

[0-9]{2}

d)

[0-9]{4}

7.

Which block is executed whether or not an exception occurs?

a)

try

b)

except

c)

finally

d)

raise

8.

How do you start a thread to run a function print_numbers() in Python?

a)

t = Thread(target=print_numbers); t.start()

b)

t = threading.Thread(print_numbers)

c)

Thread.run(print_numbers)

d)

thread.start(print_numbers)

9.

How do you create a NumPy array of integers from 1 to 10?

a)

np.array(1,2,3,...10)

b)

np.arange(1,11)

c)

np.linspace(1,10)

d)

np.list(1,10)

10.

Which function reads a CSV file into a pandas DataFrame?

a)

pd.DataFrame("sales.csv")

b)

pd.read_csv("sales.csv")

c)

pd.readfile("sales.csv")

d)

pd.csv("sales.csv")

11.

Which Tkinter widget is used to accept text input from a user?

a)

Label

b)

Entry

c)

Button

d)

Text Area

12.

In PyGame What is Sprite?

a)

Sound Effect

b)

Moving object in a game

c)

type of collision

d)

game level