wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Parithabangal 2.0

Total questions: 25

Worksheet time: 17mins

Name
Class
Date
1.

_____ represents an entity in the real world with its identity and behaviour.

a)

A method

b)

An object

c)

A class

d)

An operator

2.

What will be the output of the following Python code?

class test:

def init(self,a="Hello World"):

self.a=a  

def display(self):

print(self.a)

obj=test()

obj.display()

a)

The program has an error because constructor can’t have default arguments

b)

Nothing is displayed

c)

“Hello World” is displayed

d)

The program has an error display function doesn’t have parameters

3.

What is setattr() used for?

a)

To access the attribute of the object

b)

To set an attribute

c)

To check if an attribute exists or not

d)

To delete an attribute

4.

What will be the output of the following Python code?

class change:

def init(self, x, y, z):

self.a = x + y + z  

x = change(1,2,3)

y = getattr(x, 'a')

setattr(x, 'a', y+1)

print(x.a)

a)

6

b)

7

c)

Error

d)

0

5.

What will be the output of the following Python code?

class fruits:

def init(self, price):

self.price = price

obj=fruits(50)

  obj.quantity=10

obj.bags=2  

print(obj.quantity+len(obj.__dict__))

a)

12

b)

52

c)

13

d)

60

6.

Which of the following is not a class method?

a)

Non-static

b)

Static

c)

Bounded

d)

Unbounded

7.

What will be the output of the following Python code?

class demo():

def repr(self):

return '__repr__ built-in function called'

def str(self):

return '__str__ built-in function called'

s=demo()

print(s)

a)

Error

b)

Nothing is printed

c)

str built-in function called

d)

repr built-in function called

8.

A ________ is a description of a set of objects that share the same attributes, operations, relationships, and semantics.

a)

Structure

b)

Class

c)

Constructor

d)

Function

9.

What will be the output of the following Python code?

class A():

def disp(self):

print("A disp()")

class B(A):

pass obj = B()

obj.disp()

a)

Invalid syntax for inheritance

b)

Error because when object is created, argument must be passed

c)

Nothing is printed

d)

A disp()

10.

Which of the following is not a type of inheritance?

a)

Double-level

b)

Multi-level

c)

Single-level

d)

Multiple

11.

What type of inheritance is illustrated in the following Python code?

class A():

pass

class B():

pass

class C(A,B):

pass

a)

Multi-level inheritance

b)

Multiple inheritance

c)

Hierarchical inheritance

d)

Single-level inheritance

12.

What will be the output of the following Python code?

class A:

def init(self):

self.__i = 1

self.j = 5  

def display(self):

print(self.__i, self.j)

class B(A):

def init(self):
super().__init__()

self.__i = 2

self.j = 7

c = B()

c.display()

a)

2 7

b)

1 5

c)

1 7

d)

2 5

13.

Which of these is a private data field?

def Demo:

def init(self):

a = 1

self.b = 1

self.__c__ = 1

d= 1

a)

__a

b)

__b

c)

c

d)

d

14.

Which of the following is false about protected class members?

a)

They begin with one underscore

b)

They can be accessed by subclasses

c)

They can be accessed by name mangling method

d)

They can be accessed within a class

15.

Which operator is overloaded by invert()?

a)

!

b)

~

c)

^

d)

16.

What will be the output of the following Python code?

x = ['ab', 'cd']

print(list(map(list, x)))

a)

[‘a’, ‘b’, ‘c’, ‘d’]

b)

[[‘ab’], [‘cd’]]

c)

[[‘a’, ‘b’], [‘c’, ‘d’]]

d)

none of the mentioned

17.

What will be the output of the following Python code?

x = [12, 34]

print(len(list(map(len, x))))

a)

2

b)

1

c)

error

d)

none of the mentioned

18.

Which of the following statements is true?

a)

A non-private method in a superclass can be overridden

b)

A subclass method can be overridden by the superclass

c)

A private method in a superclass can be overridden

d)

Overriding isn’t possible in Python

19.

What will be the output of the following Python code?

def san(x):

print(x+1)

x=-2

x=4

san(12)

a)

13

b)

10

c)

2

d)

5

20.

What will be the output of the following Python code?

x=12

def f1(a,b=x):

print(a,b)

x=15

f1(4)

a)

Error

b)

12 4

c)

4 12

d)

4 15

21.

Read the following Python code carefully and point out the global variables?

y, z = 1, 2

def f():

global x

x = y+z

a)

x

b)

y and z

c)

x, y and z

d)

Neither x, nor y, nor z

22.

Who developed Python Programming Language?

a)

Wick van Rossu

b)

Rasmus Lerdorf

c)

Guido van Rossum

d)

Mr. Harirajan

23.

Which type of Programming does Python support?

a)

object-oriented programming

b)

structured programming

c)

functional programming

d)

all of the mentioned

24.

Is Python code compiled or interpreted?

a)

Python code is both compiled and interpreted

b)

Python code is neither compiled nor interpreted

c)

Python code is only interpreted

d)

Python code is only compiled

25.

Draw the Python Logo