wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

FUNCTIONS - FILES - OOPs CONCEPTS

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

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

2.

Which keyword is used for function?

a)

Fun

b)

def

c)

Def

d)

fun

3.

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

4.

Where is function defined?

a)

Module

b)

Class

c)

Another function

d)

All of the mentioned

5.

What will be the output of the following Python code?

lamb = lambda x: x ** 3

print(lamb(5))

a)

15

b)

555

c)

125

d)

Error

6.

What is the type of each element in sys.argv?

a)

int

b)

string

c)

list

d)

tuple

7.

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

8.

What is the value stored in sys.argv[0]?

a)

null

b)

you cannot access it

c)

the program’s name

d)

the first argument

9.

What happens if the base condition isn’t defined in recursive programs?

a)

Program gets into an infinite loop

b)

Program runs once

c)

Program runs n number of times where n is the argument given to the function

d)

An exception is thrown

10.

To open a file c:\scores.txt for reading, we use

a)

infile = open(“c:\scores.txt”, “r”)

b)

infile = open(“c:\\scores.txt”, “r”)

c)

infile = open(file = “c:\scores.txt”, “r”)

d)

infile = open(file = “c:\\scores.txt”, “r”)

11.

Which of the following statement is true?

a)

When you open a file for reading, if the file does not exist, an error occurs

b)

When you open a file for writing, if the file does not exist, a new file is created

c)

When you open a file for writing, if the file exists, the existing file is overwritten with the new file

d)

All of the mentioned

12.

To read the next line of the file from a file object infile, we use ____________

a)

infile.read(2)

b)

infile.read()

c)

infile.readline()

d)

infile.readlines()

13.

The readlines() method returns ____________

a)

str

b)

a list of lines

c)

a list of single characters

d)

a list of integers

14.

What is the use of tell() method in python?

a)

tells you the current position within the file

b)

tells you the end position within the file

c)

tells you the file is opened or not

d)

none of the mentioned

15.

What is the use of seek() method in files?

a)

sets the file’s current position at the offset

b)

sets the file’s previous position at the offset

c)

sets the file’s current position within the file

d)

none of the mentioned

16.

Correct syntax of file.writelines() is?

a)

file.writelines(sequence)

b)

fileObject.writelines()

c)

fileObject.writelines(sequence)

d)

none of the mentioned

17.

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

a)

Method

b)

Class

c)

Object

d)

Operator

18.

What is Instantiation in terms of OOP terminology?

a)

Deleting an instance of class

b)

Modifying an instance of class

c)

Copying an instance of class

d)

Creating an instance of class

19.

Which of the following best describes inheritance?

a)

Ability of a class to derive members of another class as a part of its own definition

b)

Means of bundling instance variables and methods in order to restrict access to certain class members

c)

Focuses on variables and passing of variables to functions

d)

Allows for implementation of elegant software that is well designed and easily modified

20.

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()

21.

Which of the following is not a type of inheritance?

a)

Double-level

b)

Multi-level

c)

Single-level

d)

Multiple

22.

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

23.

Which of the following is the most suitable definition for encapsulation?

a)

Ability of a class to derive members of another class as a part of its own definition

b)

Means of bundling instance variables and methods in order to restrict access to certain class members

c)

Focuses on variables and passing of variables to functions

d)

Allows for implementation of elegant software that is well designed and easily modified

24.

Which function is used to read all the characters?

a)

read( )

b)

readcharacters( )

c)

readall( )

d)

readchar( )

25.

What happens if no arguments are passed to the seek function?

a)

file position is set to the start of file

b)

file position is set to the end of file

c)

file position remains unchanged

d)

error