wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python quiz 2.0

Total questions: 35

Worksheet time: 14mins

Name
Class
Date
1.

Which of the following is the correct extension of the Python file?

a)

a) .python

b)

b) .pl

c)

c) .py

d)

d) .p

2.

What will be the value of the following Python expression?

4 + 3 % 5

a)

a) 7

b)

b) 2

c)

c) 4

d)

d) 1

3.

Which of the following is used to define a block of code in Python language?

a)

a) Indentation

b)

b) Key

c)

c) Brackets

d)

d) All of the mentioned

4.

Which of the following character is used to give single-line comments in Python?

a)

a) //

b)

b) #

c)

c) !

d)

d) /*

5.

What is the order of precedence in python?

a)

a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

6.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

7.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

8.

What will be the output of the following Python code?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a)

a) olleh

b)

b) hello

c)

c) h

d)

d) o

9.

What will be the output of the following Python code?

>>>str1="helloworld"

>>>str1[::-1]

a)

a) dlrowolleh

b)

b) hello

c)

c) world

d)

d) helloworld

10.

What will be the output of the “hello” +1+2+3?

a)

a) hello123

b)

b) hello

c)

c) Error

d)

d) hello6

11.

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

a)

a) 5

b)

b) 4

c)

c) None

d)

d) Error

12.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

13.

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

a)

a) [2, 33, 222, 14]

b)

b) Error

c)

c) 25

d)

d) [25, 14, 222, 33, 2]

14.

Which of the following statements create a dictionary?

a)

a) d = {}

b)

b) d = {“john”:40, “peter”:45}

c)

c) d = {40:”john”, 45:”peter”}

d)

d) All of the mentioned

15.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b)

b) Method update() doesn’t exist for dictionaries

c)

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d)

d) {4: ‘D’, 5: ‘E’}

16.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

17.

The default return value of any function in Python is _______________.

a)

null

b)

0

c)

None

d)

Garbage value

18.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

19.

Find out the rank of the given Numpy array.

(a)  

20.

What is the use of the size attribute in the NumPy array in python ?

a)

It find the direction

b)

It find the number of items

c)

It find the shape

d)

All of the above

21.

Which of the following find the maximum number in the Numpy array?

a)

max(array)

b)

array.max()

c)

array(max)

d)

None of the above

22.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
23.

What is the output of the code above

a)

None

b)

Syntax Error

c)

-1

d)

Code doesn't compile

24.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

25.

Dictionary keys must be immutable

a)

True

b)

False

26.

Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

a)

print(len(dict1))

b)

print(dict1.get("b"))

c)

dict1["a"]=5

d)

None of these.

27.

Which of the following are true for objects of Python’s set type:

a)

The order of elements in a set is significant.

b)

A given element can’t appear in a set more than once.

c)

Sets are mutable.

d)

A set may contain elements that are mutable.

28.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b)

b) Method update() doesn’t exist for dictionaries

c)

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d)

d) {4: ‘D’, 5: ‘E’}

29.

What will be the output of the following Python code?

nums = set([1,1,2,3,3,3,4,4])

print(len(nums))

a)

7

b)

Error, invalid syntax for formation of set

c)

4

d)

8

30.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

31.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a.copy()

>>> b.add(4)

>>> a

a)

{1,2,3}

b)

Error, invalid syntax for add

c)

{1,2,3,4}

d)

Error, copying of sets isn’t allowed

32.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

33.

You have the following dictionary definition:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

34.

What is the output of the code shown in the image?

a)

2

b)

3

c)

'2'

d)

'3'

35.

If a=(1,2,3,4), a[1:-1] is _________

a)

a) Error, tuple slicing doesn’t exist

b)

b) [2,3]

c)

c) (2,3,4)

d)

d) (2,3)