Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 31

Worksheet time: 16mins

Name
Class
Date
1.

What is the output of the following code? t = (1, 2, 3) + (4, 5) print(t)

a)

(1, 2, 3, 4, 5)

b)

(5, 4, 3, 2, 1)

c)

[1, 2, 3, 4, 5]

d)

(1, 2, 3), (4, 5)

2.

What method is used to remove a specific value from a list?

a)

remove()

b)

pop()

c)

delete()

d)

del

3.

The ______ function returns a new sorted list from any sequence.

a)

sorted

b)

sort

c)

sorted_list

d)

order

4.

The update method is used to merge one dictionary into another.

a)

True

b)

False

5.

Which method is used to check if a dictionary contains a specific key?

a)

in

b)

contains()

c)

has_key()

d)

key_check()

6.

The pandas library provides high-level data structures for working with structured and tabular data.

a)

True

b)

False

7.

Which of the following is a mutable object in Python?

a)

String

b)

Tuple

c)

List

d)

None

8.

What will be the output of this code? x = 10; y = 3; print(x // y)

a)

3.33

b)

3

c)

3.0

d)

4

9.

Output of this code: nums = [1,2,3]; print(sum(nums))

a)

6

b)

5

c)

3

d)

Error

10.

What does the following code print? a = [1,2,3]; print(a[::-1])

a)

[3,2,1]

b)

[1,2,3]

c)

[1,3,2]

d)

Error

11.

What is the result? import numpy as np a = np.zeros((2,3))

a)

Array of zeros with shape (2,3)

b)

Array of ones

c)

Empty array

d)

Error

12.

What does the following code return? lst = [1,2,3,4] print(lst.index(3))

a)

2

b)

3

c)

1

d)

Error

13.

Which of the following is not a valid input for creating a DataFrame?

a)

A single integer

b)

A dictionary of lists

c)

A NumPy array

d)

A list of dictionaries

14.

What does this code print? import numpy as np a = np.array([[1, 2], [3, 4]]) print(a.shape)

a)

(2, 2)

b)

(2,)

c)

(4,)

d)

Error

15.

Output of the following code? import numpy as np a = np.array([1,2,3]) print(a.dtype)

a)

int64

b)

float64

c)

object

d)

Error

16.

What is the result? import numpy as np a = np.zeros((2,3))

a)

Array of zeros with shape (2,3)

b)

Array of ones

c)

Empty array

d)

Error

17.

Output of this code? import numpy as np a = np.array([1,2,3,4]) print(np.where(a>2))

a)

(array([2,3]),)

b)

(array([0,1]),)

c)

[3 4]

d)

Error

18.

Output of this code: d = {"a":1, "b":2} print(d.get("c", 0))

a)

0

b)

None

c)

Error

19.

The with statement is used to handle ______ safely and ensure they are closed properly.

a)

files

b)

loops

c)

functions

d)

variables

20.

What is the output of the following code? import numpy as np a = np.array([1, 2, 3]) print(a[1])

a)

2

b)

1

c)

3

d)

Error

21.

What does this print? import numpy as np print(np.unique([1,2,2,3,3,4]))

a)

[1 2 3 4]

b)

[1 2 2 3 3 4]

c)

[2 3 4]

d)

Error

22.

What is a key difference between a pandas Series and a DataFrame?

a)

A Series is one-dimensional, while a DataFrame is two-dimensional.

b)

A Series can contain multiple data types, while a DataFrame cannot.

c)

A DataFrame does not have indexes, while a Series always does.

d)

Both are always empty by default.

23.

Which method allows you to select data from a DataFrame by row and column labels?

a)

loc

b)

iloc

c)

index

d)

slice

24.

What will the following code output? import pandas as pd data = {"A": [1, 2], "B": [3, 4]} df = pd.DataFrame(data) print(df.iloc[1])

a)

A 2 B 4 (Series)

b)

A 1 B 3

c)

[1, 3]

d)

Error

25.

What will the following code output? import pandas as pd s = pd.Series([1, 2, 3], index=["a", "b", "c"]) print(s["b"])

a)

2

b)

1

c)

“b”

d)

Error

26.

What does this code return? import pandas as pd df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6]}) print(df[df['A']>1])

a)

Rows with A=2 and A=3

b)

Row with A=1

c)

[2,3]

d)

Error

27.

Output of this code? import pandas as pd df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6]}) print(df.iloc[1,1])

a)

5

b)

2

c)

4

d)

Error

28.

What does the following code produce? import pandas as pd df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6]}) print(df.loc[0,'B'])

a)

4

b)

1

c)

0

d)

Error

29.

Which library is typically used to read and parse Excel files in pandas?

a)

openpyxl

b)

pickle

c)

lxml

d)

json

30.

Which pandas method writes a DataFrame to pickle format?

a)

to_pickle()

b)

write_pickle()

c)

to_binary()

d)

pickle_dump()

31.

What does this code output? import pandas as pd df = pd.read_csv('data.csv', thousands=',')

a)

Converts numbers like ‘1,000’ to 1000

b)

Treats ‘,’ as delimiter

c)

Reads all values as strings

d)

Error