Question
1. The output of the following two Python codes is exactly the same. object 'a' CODE 1 >>> pickle.dumps('a', 3) CODE 2 >>> pickle.dumps(object, 3)
1. The output of the following two Python codes is exactly the same.
object
'a'
CODE 1
>>> pickle.dumps('a', 3)
CODE 2
>>> pickle.dumps(object, 3)
a) True
b) False
2. What will be the output of the following Python code?
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
a)
Hello
WorldWorldWorldWorldWorld
b)
Hello
World 5
c)
Hello
World,World,World,World,World
d)
Hello
HelloHelloHelloHelloHello
3. What will be the output of the following Python code?
re.subn('A', 'X', 'AAAAAA', count=4)
a) 'XXXXAA, 4'
b) ('AAAAAA', 4)
c) ('XXXXAA', 4)
d) 'AAAAAA, 4'
4. What will be the output of the following Python code?
x=100
def f1():
global x
x=90
def f2():
global x
x=80
print(x)
a) 100
b) 90
c) 80
d) Error
5. Point out the error (if any) in the code shown below if the system date is 18th June, 2017?
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
till_bday=bday-tday
print(till_bday)
a) 3 months, 0:00:00
b) 90 days, 0:00:00
c) 3 months 2 days, 0:00:00
d) 92 days, 0:00:00
6. Which of the following is false about protected class members?
a) They begin with one underscore
b) They can be accessed by subclasses
c) They can be accessed by name mangling method
d) They can be accessed within a class
7. What is returned by math.expm1(p)?
a) (math.e ** p) - 1
b) math.e ** (p - 1)
c) error
d) none of the mentioned
8. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a) True
b) False
c) Error
d) None
9. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
a) True
b) False
c) None
d) Error
10. What will be the output of the following Python code?
x = ['ab', 'cd']
print(list(map(list, x)))
a) ['a', 'b', 'c', 'd']
b) [['ab'], ['cd']]
c) [['a', 'b'], ['c', 'd']]
d) none of the mentioned
11. What does math.sqrt(X, Y) do?
a) calculate the Xth root of Y
b) calculate the Yth root of X
c) error
d) return a tuple with the square root of X and Y
12. What is the output of print(math.trunc('3.1'))?
a) 3
b) 3.0
c) error
d) none of the mentioned
13. What will be the output of the following Python code?
x = [[0], [1]]
print(len(' '.join(list(map(str, x)))))
a) 2
b) 3
c) 7
d) 8
14. What will be the output of the following Python code?
import time
t=(2010, 9, 20, 8, 15, 12, 6)
time.asctime(t)
a) '20 Sep 2010 8:15:12 Sun'
b) '2010 20 Sept 08:15:12 Sun'
c) 'Sun Sept 20 8:15:12 2010'
d) Error
15. What will be the output of the following Python code?
def f(x):
yield x+1
print("test")
yield x+2
g=f(9)
a) Error
b) test
c)
test
10
12
d) No output
16. What is x if x = math.isfinite(float('0.0'))?
a) True
b) False
c) None
d) error
17. How do you change the file position to an offset value from the start?
a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned
18. Which of the following is not a valid attribute of a file object (fp)?
a) fp.name
b) fp.closed
c) fp.mode
d) fp.size
19. What will be the output of the following Python code snippet?
a={}
a['a']=1
a['b']=[2,3,4]
print(a)
a) Exception is thrown
b) {'b': [2], 'a': 1}
c) {'b': [2], 'a': [3]}
d) {'b': [2, 3, 4], 'a': 1}
20. Is the following Python code correct?
>>> class A:
def __init__(self,b):
self.b=b
def display(self):
print(self.b)
>>> obj=A("Hello")
>>> del obj
a) True
b) False
21. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
a) True
b) False
c) None
d) Error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started