NEW
Font size
WorksheetsFUNCTIONS - FILES - OOPs CONCEPTS
Total questions: 25
Worksheet time: 13mins
Which of the following is the use of function in python?
Functions are reusable pieces of programs
Functions don’t provide better modularity for your application
you can’t also create your own functions
All of the mentioned
Which keyword is used for function?
Fun
def
Def
fun
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 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
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
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
Error
Where is function defined?
Module
Class
Another function
All of the mentioned
What will be the output of the following Python code?
lamb = lambda x: x ** 3
print(lamb(5))
15
555
125
Error
What is the type of each element in sys.argv?
int
string
list
tuple
How are variable length arguments specified in the function heading?
one star followed by a valid identifier
one underscore followed by a valid identifier
two stars followed by a valid identifier
two underscores followed by a valid identifier
What is the value stored in sys.argv[0]?
null
you cannot access it
the program’s name
the first argument
What happens if the base condition isn’t defined in recursive programs?
Program gets into an infinite loop
Program runs once
Program runs n number of times where n is the argument given to the function
An exception is thrown
To open a file c:\scores.txt for reading, we use
infile = open(“c:\scores.txt”, “r”)
infile = open(“c:\\scores.txt”, “r”)
infile = open(file = “c:\scores.txt”, “r”)
infile = open(file = “c:\\scores.txt”, “r”)
Which of the following statement is true?
When you open a file for reading, if the file does not exist, an error occurs
When you open a file for writing, if the file does not exist, a new file is created
When you open a file for writing, if the file exists, the existing file is overwritten with the new file
All of the mentioned
To read the next line of the file from a file object infile, we use ____________
infile.read(2)
infile.read()
infile.readline()
infile.readlines()
The readlines() method returns ____________
str
a list of lines
a list of single characters
a list of integers
What is the use of tell() method in python?
tells you the current position within the file
tells you the end position within the file
tells you the file is opened or not
none of the mentioned
What is the use of seek() method in files?
sets the file’s current position at the offset
sets the file’s previous position at the offset
sets the file’s current position within the file
none of the mentioned
Correct syntax of file.writelines() is?
file.writelines(sequence)
fileObject.writelines()
fileObject.writelines(sequence)
none of the mentioned
_____ represents an entity in the real world with its identity and behaviour.
Method
Class
Object
Operator
What is Instantiation in terms of OOP terminology?
Deleting an instance of class
Modifying an instance of class
Copying an instance of class
Creating an instance of class
Which of the following best describes inheritance?
Ability of a class to derive members of another class as a part of its own definition
Means of bundling instance variables and methods in order to restrict access to certain class members
Focuses on variables and passing of variables to functions
Allows for implementation of elegant software that is well designed and easily modified
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()
Invalid syntax for inheritance
Error because when object is created, argument must be passed
Nothing is printed
A disp()
Which of the following is not a type of inheritance?
Double-level
Multi-level
Single-level
Multiple
What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
pass
class C(A,B):
pass
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
Which of the following is the most suitable definition for encapsulation?
Ability of a class to derive members of another class as a part of its own definition
Means of bundling instance variables and methods in order to restrict access to certain class members
Focuses on variables and passing of variables to functions
Allows for implementation of elegant software that is well designed and easily modified
Which function is used to read all the characters?
read( )
readcharacters( )
readall( )
readchar( )
What happens if no arguments are passed to the seek function?
file position is set to the start of file
file position is set to the end of file
file position remains unchanged
error
