Functions

1
Question 1
What will be the output of the following code :
print type(type(int))
A
type 'int'
B
type 'type'
C
Error
D
0
Functions    
Discuss it


Question 1 Explanation: 
The type() function returns the class of the argument the object belongs to. Thus, type(int) returns which is of the type ‘type’ object.
Question 2
What is the output of the following code :
L = ['a','b','c','d']
print "".join(L)
A
Error
B
None
C
abcd
D
[‘a’,’b’,’c’,’d’]
Functions    
Discuss it


Question 2 Explanation: 
“” depicts a null string and the join function combines the elements of the list into a string.
Question 3
What is the output of the following segment :
chr(ord('A'))
A
A
B
B
C
a
D
Error
Functions    
Discuss it


Question 3 Explanation: 
ord() function converts a character into its ASCII notation and chr() converts the ASCII to character.
Question 4
What is the output of the following program :
y = 8
z = lambda x : x * y
print z(6)
A
48
B
14
C
64
D
None of the above
Functions    
Discuss it


Question 4 Explanation: 
lambdas are concise functions and thus, result = 6 * 8
Question 5
What is called when a function is defined inside a class?
A
Module
B
Class
C
Another Function
D
Method
Functions    
Discuss it


Question 6
Which of the following is the use of id() function in python?
A
Id returns the identity of the object
B
Every object doesn’t have a unique id
C
All of the mentioned
D
None of the mentioned
Functions    
Discuss it


Question 6 Explanation: 
Each object in Python has a unique id. The id() function returns the object’s id.
Question 7
What is the output of the following program :
import re
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groupdict())
A
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
B
(‘horses’, ‘are’, ‘fast’)
C
‘horses are fast’
D
‘are’
Functions    
Discuss it


Question 7 Explanation: 
This function returns a dictionary that contains all the matches.
Question 8
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?
A
[3, 4, 5, 20, 5, 25, 1, 3]
B
[1, 3, 3, 4, 5, 5, 20, 25]
C
[3, 5, 20, 5, 25, 1, 3]
D
[1, 3, 4, 5, 20, 5, 25]
Functions    
Discuss it


Question 8 Explanation: 
pop(i) removes the ith index element from the list
Question 9
time.time() returns ________
A
the current time
B
the current time in milliseconds
C
the current time in milliseconds since midnight
D
the current time in milliseconds since midnight, January 1, 1970
E
the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
Functions    
Discuss it


There are 9 questions to complete.
1

Company Wise Coding Practice    Topic Wise Coding Practice