Python Miscellaneous

Question 1

What is the output of the following program : 

Python3

print "Hello World"[::-1]
Tick

dlroW olleH

Cross

Hello Worl

Cross

d

Cross

Error



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?
Cross
int
Cross
bool
Cross
void
Tick
None


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?
Tick
re
Cross
regex
Cross
pyregex
Cross
None of the above


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 : 

Python3

print 0.1 + 0.2 == 0.3
Cross

True

Tick

False

Cross

Machine dependent

Cross

Error



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?
Cross
k = 2 + 3j
Cross
k = complex(2, 3)
Tick
k = 2 + 3l
Cross
k = 2 + 3J


Question 5-Explanation: 
l (or L) stands for long.
Question 6
What does ~~~~~~5 evaluate to?
Tick
+5
Cross
-11
Cross
+11
Cross
-5


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


Question 7-Explanation: 
strings are immutable in Python
Question 8
________ is a simple but incomplete version of a function.
Tick
Stub
Cross
Function
Cross
A function developed using bottom-up approach
Cross
A function developed using top-down approach


Question 9
To start Python from the command prompt, use the command ______
Cross
execute python
Cross
go python
Tick
python
Cross
run python


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


There are 10 questions to complete.

  • Last Updated : 10 Mar, 2018

Share your thoughts in the comments
Similar Reads