Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python and NumPy Quiz

Total questions: 44

Worksheet time: 38mins

Name
Class
Date
1.

Which of the following is mutable?

a)

tuple

b)

string

c)

list

d)

int

2.

What does len("Hello\nWorld") return?

a)

10

b)

11

c)

12

d)

9

3.

What is the output of print(3 * 'abc')?

a)

abcabcabc

b)

abc3

c)

abc abc abc

d)

Error

4.

Which keyword is used to define a function in Python?

a)

func

b)

define

c)

def

d)

function

5.

What is the output of bool([])?

a)

True

b)

False

c)

None

d)

Error

6.

Which of the following will raise an error?

a)

int("123")

b)

int("12.3")

c)

int(12.3)

d)

int(True)

7.

What is the output of print("Python"[::-1])?

a)

nohtyP

b)

Python

c)

nothyP

d)

Error

8.

Which of the following is not a valid Python data type?

a)

set

b)

dict

c)

array

d)

list

9.

What is the output of print(2 ** 3 ** 2)?

a)

64

b)

512

c)

256

d)

8

10.

Which function creates an array of zeros?

a)

np.zeros()

b)

np.empty()

c)

np.ones()

d)

np.full()

11.

What is the output of np.array([1, 2, 3]).shape?

a)

(3,)

b)

(1,3)

c)

(3,1)

d)

[3]

12.

Which function returns evenly spaced values over a specified interval?

a)

np.linspace()

b)

np.arange()

c)

np.range()

d)

np.split()

13.

What does np.eye(3) produce?

a)

Identity matrix

b)

Diagonal matrix

c)

Zero matrix

d)

Error

14.

What is the output of np.array([1, 2, 3]) + np.array([4, 5, 6])?

a)

[5, 7, 9]

b)

[1, 2, 3, 4, 5, 6]

c)

Error

d)

[4, 5, 6]

15.

Which method flattens a NumPy array?

a)

flatten()

b)

reshape(-1)

c)

ravel()

d)

All of the above

16.

What is the output of np.arange(1, 5, 2)?

a)

[1, 3]

b)

[1, 2, 3, 4]

c)

[1, 3, 5]

d)

[1, 2, 5]

17.

Which function computes the mean of an array?

a)

np.mean()

b)

np.average()

c)

np.median()

d)

np.sum()

18.

What does np.dot() do?

a)

Element-wise multiplication

b)

Matrix multiplication

c)

Transpose

d)

Scalar multiplication

19.

Which of the following raises an error? python a = np.array([1, 2]) b = np.array([[1, 2], [3, 4]]) print(a + b)

a)

[2, 4], [4, 6]

b)

Error

c)

[2, 4]

d)

[1, 2, 3, 4]

20.

What is the output of np.array([[1,2],[3,4]]).T?

a)

[[1,3],[2,4]]

b)

[[1,2],[3,4]]

c)

[[2,1],[4,3]]

d)

Error

21.

Which function returns the maximum value in an array?

a)

np.max()

b)

np.maximum()

c)

np.argmax()

d)

np.sort()

22.

What is the output of np.array([1,2,3]) > 2?

a)

[False, False, True]

b)

[True, True, False]

c)

[1,2,3]

d)

Error

23.

Which function stacks arrays vertically?

a)

np.vstack()

b)

np.hstack()

c)

np.stack()

d)

np.concat()

24.

What is the output of np.array([1,2,3]).dtype?

a)

int64

b)

float64

c)

object

d)

str

25.

Which function is used to plot a line graph?

a)

plt.plot()

b)

plt.line()

c)

plt.graph()

d)

plt.show()

26.

What does plt.show() do?

a)

Displays the plot

b)

Saves the plot

c)

Clears the plot

d)

Creates a figure

27.

Which function sets the title of a plot?

a)

plt.title()

b)

plt.set_title()

c)

plt.name()

d)

plt.heading()

28.

What is the output of this code? python import matplotlib.pyplot as plt plt.plot([1,2,3],[4,5,6]) plt.show()

a)

Line graph from (1,4) to (3,6)

b)

Bar chart

c)

Error

d)

Empty plot

29.

Which function adds a legend to the plot?

a)

plt.legend()

b)

plt.label()

c)

plt.key()

d)

plt.info()

30.

What does plt.xlabel("X-axis") do?

a)

Sets label for x-axis

b)

Sets label for y-axis

c)

Sets title

d)

Adds legend

31.

Which function creates a histogram?

a)

plt.hist()

b)

plt.bar()

c)

plt.plot()

d)

plt.scatter()

32.

What does plt.savefig("plot.png") do?

a)

Saves the plot as PNG

b)

Displays the plot

c)

Deletes the plot

d)

Converts plot to array

33.

What is the output of np.array([[1, 2], [3, 4]]).flatten()?

a)

[1, 3, 2, 4]

b)

Error

c)

[1, 2, 3, 4]

d)

[[1, 2], [3, 4]]

34.

Which function is used to create a scatter plot?

a)

plt.bar()

b)

plt.plot()

c)

plt.scatter()

d)

plt.hist()

35.

What is the output of len([1, 2, 3, 4])?

a)

5

b)

Error

c)

3

d)

4

36.

What does plt.ylabel("Y-axis") do?

a)

Adds grid

b)

Sets title

c)

Sets label for x-axis

d)

Sets label for y-axis

37.

Which function is used to concatenate two arrays?

a)

np.join()

b)

np.merge()

c)

np.append()

d)

np.concatenate()

38.

What is the output of np.zeros((2, 3))?

a)

[[1, 1, 1], [1, 1, 1]]

b)

[[2, 2, 2], [2, 2, 2]]

c)

Error

d)

[[0, 0, 0], [0, 0, 0]]

39.

What does plt.ylabel("Y-axis") do?

a)

Adds grid

b)

Sets label for y-axis

c)

Sets label for x-axis

d)

Sets title

40.

Which function is used to create a bar chart?

a)

plt.bar()

b)

plt.plot()

c)

plt.scatter()

d)

plt.hist()

41.

What is the output of np.array([[1, 2], [3, 4]]).sum()?

a)

Error

b)

[1, 2, 3, 4]

c)

10

d)

7

42.

Which function generates a sequence of numbers?

a)

np.range()

b)

np.linspace()

c)

np.arange()

d)

np.sequence()

43.

What does np.unique() do?

a)

Reshapes an array

b)

Counts elements in an array

c)

Sorts an array

d)

Finds unique elements in an array

44.

Which function is used to concatenate two arrays?

a)

np.join()

b)

np.merge()

c)

np.append()

d)

np.concatenate()