wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Season 1 #Spaic Python Weekly Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Why are local variable names beginning with an underscore discouraged?

a)

They are used to indicate a private variables of a class

b)

They confuse the interpreter

c)

They are used to indicate global variables

d)

They slow down execution

2.

What will be the output of the following Python code?

a)

[‘ab’, ‘cd’]

b)

[‘AB’, ‘CD’]

c)

[None, None]

d)

None of the mentioned

3.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

None of the mentioned

4.

Point out the correct statement.

a)

If data is a list, if index is passed the values in data corresponding to the labels in the index will be pulled out

b)

NaN is the standard missing data marker used in pandas

c)

Series acts very similarly to a array

d)

None of the mentioned

5.

Given a function that does not return any value, What value is thrown by default when executed in shell.

a)

Int

b)

Bool

c)

Void

d)

None

6.

What error occurs when you execute the following Python code snippet? apple = mango

a)

SyntaxError

b)

NameError

c)

ValueError

d)

TypeError

7.

Which of the following operators has its associativity from right to left?

a)

+

b)

//

c)

%

d)

**

8.

 a=[1,2,3,4,5]  b=[6,7,8,9]a=[1,2,3,4,5]\ \ b=\left[6,7,8,9\right]  Which of the following would create a list which has all the elements of a and b in one dimension

a)

a.append(b)

b)

a.extend(b)

c)

Any of the above

d)

None of these

9.

 tup=(1,2,3,4,5)tup=(1,2,3,4,5)  You want to update the value of the tuple at the 2nd index to 10 Which is the correct way to do this?

a)

tup(2) = 10

b)

Tup[2] = 10

c)

Tup{2} = 10

d)

None of these

10.

 CityA=[1,2,3,4]  City_A=[“1”,”2”,”3”,”4”]\ \    CityB=[2,3,4,5]City_B=[“2”,”3”’,”4”,”5”]  Using this two lists ,Which of the following will find the names of cities in City_A but not in City_B


a)

[i for i in City_A if i not in City_B]

b)

[i for i in City_B if i not in City_A]

c)

[i for i in City_A if i in City_B]

d)

None of the above

11.

In Python, lists and Dictionaries can store multiple data types

a)

True

b)

False

12.

If you want to check membership of an element in a collection, which data type will allow you to do this faster

a)

List

b)

Set

13.

What is the result of print (list[2:]) if list = [1,4,5,2,3]

a)

[2,3]

b)

[1,4,5,2]

c)

[5,2,3]

d)

[4,2]

14.

Which are more compact and implemented more efficiently

a)

Python lists

b)

NumPy arrays

15.

What does the ‘’.join() operation allow you to do

a)

Convert a string to a list

b)

Convert a list of strings to a string

16.

Which of the following randomizes the items of a list in place?

a)

shuffle(list)

b)

capitalize(list)

c)

rand(list)

d)

isdigit(list)

17.

What data type is the object below? L = [1, 23, 'apple', 1]

a)

List

b)

Dictionary

c)

Array

d)

Tuple

18.

What arithmetic operators cannot be used with strings?

a)

+

b)

*

c)

d)

All of the mentioned

19.

Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?

a)

5

b)

4

c)

None

d)

Error

20.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

[2, 33, 222, 14]

b)

Error

c)

25

d)

[25, 14, 222, 33, 2]