Miscellaneous

1
Question 1
What is the output of the following program :
print "Hello World"[::-1]
A
dlroW olleH
B
Hello Worl
C
d
D
Error
Miscellaneous    
Discuss it


Question 1 Explanation: 
[::] depicts extended slicing in Python and [::-1] returns the reverse of the string.
Question 2
Given a function that does not return any value, what value is shown when executed at the shell?
A
int
B
bool
C
void
D
None
Miscellaneous    
Discuss it


Question 2 Explanation: 
Python explicitly defines the None object that is returned if no value is specified.
Question 3
Which module in Python supports regular expressions?
A
re
B
regex
C
pyregex
D
None of the above
Miscellaneous    
Discuss it


Question 3 Explanation: 
re is a part of the standard library and can be imported using: import re.
Question 4
What is the output of the following program :
print 0.1 + 0.2 == 0.3
A
True
B
False
C
Machine dependent
D
Error
Miscellaneous    
Discuss it


Question 4 Explanation: 
Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.
Question 5
Which of the following is not a complex number?
A
k = 2 + 3j
B
k = complex(2, 3)
C
k = 2 + 3l
D
k = 2 + 3J
Miscellaneous    
Discuss it


Question 5 Explanation: 
l (or L) stands for long.
Question 6
What does ~~~~~~5 evaluate to?
A
+5
B
-11
C
+11
D
-5
Miscellaneous    
Discuss it


Question 6 Explanation: 
~x is equivalent to -(x+1).
Question 7
Given a string s = “Welcome”, which of the following code is incorrect?
A
print s[0]
B
print s.lower()
C
s[1] = ‘r’
D
print s.strip()
Miscellaneous    
Discuss it


Question 7 Explanation: 
strings are immutable in Python
Question 8
________ is a simple but incomplete version of a function.
A
Stub
B
Function
C
A function developed using bottom-up approach
D
A function developed using top-down approach
Miscellaneous    
Discuss it


Question 9
To start Python from the command prompt, use the command ______
A
execute python
B
go python
C
python
D
run python
Miscellaneous    
Discuss it


Question 10
Which of the following is correct about Python?
A
It supports automatic garbage collection.
B
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java
C
Both of the above
D
None of the above
Miscellaneous    
Discuss it


There are 10 questions to complete.
1

Company Wise Coding Practice    Topic Wise Coding Practice