wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OOPs with Python

Total questions: 59

Worksheet time: 48mins

Name
Class
Date
1.

OOPs

a)

Object Oriented Program

b)

Object Oriented Programming

c)

Object Opted Programming

d)

Objective Oriented Programming

2.

What create objects?

a)

Classes

b)

Functions

c)

Methods

d)

Modules

3.

What are classes?

a)

Blueprints/

Prototypes that defines methods and attributes

b)

A thing which creates objects

c)

A set of attributes and methods

d)

A Blueprint of methods

4.

What are Objects

a)

Instances of a Class

b)

Calling of a class

c)

Identity of a class

d)

Usables of a class

5.

What are Attributes

a)

Functions of a class

b)

Variables of a class

c)

Instance of a class

d)

Variables of a code

6.

What do Objects represent?

a)

Uniqueness

b)

Identity

c)

Instance

d)

Class

7.

What refers to the Behavior of a class?

a)

Attributes

b)

Methods

c)

Constructors

d)

Self

8.

What refers to the behavior of the class

a)

Attribute

b)

Class

c)

Object

d)

Method

9.

what is self?

a)

Self represents the instance of the class in the class

b)

Binds the Attr and methods

c)

A default thing in classes with no use

d)

None of the Above

10.

How to call a method?

a)

Obj.method

b)

Obj.method()

c)

Method(object)

d)

Method.object

11.

Making of a class

a)

class NAME:

b)

class NAME():

c)

class (NAME):

d)

class: Name()

12.

Which of the following is the use of function in python?

a)

Functions are reusable pieces of programs

b)

Functions don’t provide better modularity for your application

c)

you can’t also create your own functions

d)

All of the mentioned

13.

Which keyword is used for function?

a)

Fun

b)

def

c)

Def

d)

fun

14.

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

a)

A method

b)

An object

c)

A class

d)

An operator

15.

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

class X():

pass

class Y():

pass

class Z(X,Y):

pass

a)

Multi-level inheritance

b)

Multiple inheritance

c)

Hierarchical inheritance

d)

Single-level inheritance

16.

What will be the output of the following Python code?


class A:

def __init__(self):

self._x = 7


class B(A):

def display(self):

print(self._x)


def main():

obj = B()

obj.display()


main()

a)

Error, invalid syntax for object declaration

b)

Nothing is printed

c)

7

d)

Error, private class member can’t be accessed in a subclass

17.

What will be the output of the following Python code?

def say(message, times = 1):

print(message * times)


say('Hello')

say('World', 5)

a)

Hello

WorldWorldWorldWorldWorld

b)

Hello

World 5

c)

Hello

World,World,World,World,World

d)

Hello

HelloHelloHelloHelloHello

18.

What will be the output of the following Python code?

def func(a, b=5, c=10):

print('a is', a, 'and b is', b, 'and c is', c)


func(3, 7)

func(25, c = 24)

func(c = 50, a = 100)

a)

a is 7 and b is 3 and c is 10

a is 25 and b is 5 and c is 24

a is 5 and b is 100 and c is 50

b)

a is 3 and b is 7 and c is 10

a is 5 and b is 25 and c is 24

a is 50 and b is 100 and c is 5

c)

a is 3 and b is 7 and c is 10

a is 25 and b is 5 and c is 24

a is 100 and b is 5 and c is 50

d)

Error

19.

What will be the output of the following Python code?

a=15

b=25


def change():

global b

a=60

b=70


change()

print(a)

print(b)

a)

15

70

b)

60

70

c)

15

25

d)

Error

20.

How are variable length arguments specified in the function heading?

a)

one star followed by a valid identifier

b)

one underscore followed by a valid identifier

c)

two stars followed by a valid identifier

d)

two underscores followed by a valid identifier

21.

What will be the output of the following Python code?

class A:

def test1(self):

print(" test of A called ")


class B(A):

def test(self):

print(" test of B called ")


class C(A):

def test(self):

print(" test of C called ")


class D(B,C):

def test2(self):

print(" test of D called ")


obj=D()

obj.test()

a)

test of B called

test of C called

b)

test of C called

test of B called

c)

test of B called

d)

Error, both the classes from which D derives has same method test()

22.

What is the difference between a class and an object?

a)

A class is a blueprint to create an object

b)

An object is a blueprint to create a class

c)

A blueprint is an object to create a class

d)

Blueprint class is an object to create

23.
These have identitystate, and behavior.
a)
class
b)
object
c)
method
d)
void
24.

Functions as Arguments

What does the code below print?

def sq(func, x):

y = x**2

return func(y)


def f(x):

return x**2


calc = sq(f, 2)

print(calc)

a)

4

b)

8

c)

16

d)

nothing, it will show an error

25.

Function Calls

How many total lines of output will show up if you run the code below?

def add(x, y):

return x+y


def mult(x, y):

print(x*y)


add(5,3)

print(add(3,4))

mult(2,6)

print(mult(4,2))

a)

0

b)

2

c)

4

d)

6

26.

Exceptions


try:

n = int(input("How old are you? "))

percent = round(n*100/80, 1)

print("You've gone through", percent, "% of your life!")

except ValueError:

print("Oops, must enter a number.")

except ZeroDivisionError:

print("Division by zero.")

except:

print("Something went very wrong.")


If the user enters "1" in the code above what does the program do?

a)

prints "You've gone through 1.3 % of your life!"

b)

prints "Something went very wrong."

27.

If the user enters "thirty" in the code below what does the program do?

try:

n = int(input("How old are you? "))

percent = round(n*100/80, 1)

print("You've gone through", percent, "% of your life!")

except ValueError:

print("Oops, must enter a number.")

except ZeroDivisionError:

print("Division by zero.")

except:

print("Something went very wrong.")

a)

prints "You've gone through 37.5 % of your life!"

b)

prints "Division by zero."

28.

Suppose C is a subclass of D, to invoke the __init__ method in D from C, what is the line of code you should write?

a)

D.__init__(self)

b)

C.__init__(self)

c)

D.__init__(C)

d)

C.__init__(D)

29.

a)

Error because class B inherits A but variable x isn’t inherited

b)

0 0

c)

0 1

d)

Error, the syntax of the invoking method is wrong

30.
a)

Error, the syntax of the invoking method is wrong

b)

The program runs fine but nothing is printed

c)

1 0

d)

1 2

31.
a)

Error as age isn’t defined

b)

True

c)

False

d)

7

32.
a)

Old

b)

New

c)

error

d)

Nothing is printed

33.
a)

12

b)

52

c)

13

d)

60

34.

As a Vehicle user, we know how to use it but its internal working are not known. In OOPs Concept, this principle is known as

a)

Encapsulation

b)

Inheritance

c)

Abstraction

d)

Polymorphism

35.

people = ["Alice", "Eve", "Mallory"]

print (people[2])

what would this result be?

a)

Alice

b)

Eve

c)

Mallory

d)

Error

36.

What does __init__ do?

a)

Constructs the instance

b)

Initialize the instance values

c)

Calls the Super class

d)

Creates a circle

37.

What will be the output of the following Python code?


class A:

def __init__(self):

self._x = 7


class B(A):

def display(self):

print(self._x)


def main():

obj = B()

obj.display()


main()

a)

Error, invalid syntax for object declaration

b)

Nothing is printed

c)

7

d)

Error, private class member can’t be accessed in a subclass

38.
These have identitystate, and behavior.
a)
class
b)
object
c)
method
d)
void
39.

Which keyword is used for function?

a)

fun

b)

define

c)

def

d)

function

40.

What will be the output of the following Python code?

>>> lamb = lambda x: x ** 3

>>> print(lamb(7))

a)

21

b)

343

c)

49

d)

Error

41.

Decides if a string only contains numbers

a)

isdigit()

b)

isnumeric()

c)

float()

d)

str()

42.
Python identifies blocks of code by
a)
BEGIN and END keywords
b)
{ and }
c)
aligning up the starts of lines (indentation)
d)
guessing
43.

If you want to check for multiple conditions in your code, what do you use (after if)?

a)

elif

b)

else

c)

ifif

44.

Which of the following blocks will be executed whether an exception is thrown or not?

a)

except

b)

finally

c)

else

d)

raise

45.

The purpose of name mangling is to avoid unintentional access of private class members. True or False?

a)

May be

b)

True

c)

False

d)

None

46.

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

47.

Overriding means changing behaviour of methods of derived class methods in the base class. Is the statement true or false?

a)

True

b)

False

c)

None

d)

May be

48.

What is the output of the following code, if the time module has already been imported?

4 + '3'

a)

NameError

b)

IndexError

c)

ValueError

d)

TypeError

49.

The output of the code shown below is:

int("gprec")

a)

ImportError

b)

ValueError

c)

TypeError

d)

NameError

50.

Can one block of except statements handle multiple exception?

a)

yes

b)

no

c)

yes, like except TypeError, SyntaxError [,…].

d)

yes, like except [TypeError, SyntaxError].

51.

When is the finally block executed?

a)

when there is no exception

b)

when there is an exception

c)

only if some condition that has been specified is satisfied

d)

always

52.

Pure OOP can be implemented without using class in a program. (True or False)

a)

True

b)

False

53.

Which Feature of OOP illustrated the code reusability?

a)

Polymorphism

b)

Abstraction

c)

Encapsulation

d)

Inheritance

54.

Which of the following is associated with objects?

a)

State

b)

Behaviour

c)

Identity

d)

All the above

55.

Combining Data and Functions into a single unit is called

a)

Abstraction

b)

Inheritance

c)

Encapsulation

d)

Polymorphism

56.

Advantages of OOPs

a)

Code Reusability

b)

Modular Programming

c)

Easy Maintenance

d)

Security

57.

What is the purpose of the 'self' keyword in Python classes?

a)

To refer to the current instance of the class

b)

To create a new instance of the class

c)

To access class-level variables

d)

To define a private method

58.

What is the output of the following Python code?

class A:

def __init__(self):

self._y = 10


class B(A):

def display(self):

print(self._y)


def main():

obj = B()

obj.display()


main()

a)

Error, invalid syntax for object declaration

b)

Nothing is printed

c)

10

d)

Error, private class member can’t be accessed in a subclass

59.

What is the purpose of the 'finally' block in Python exception handling?

a)

To handle the exception if it occurs

b)

To execute code regardless of whether an exception is thrown or not

c)

To raise a custom exception

d)

To specify the type of exception to catch