Question
1. What will be the output of the following Python code? import datetime d=datetime.date(2017,06,18) print(d) a) Error b) 2017-06-18 c) 18-06-2017 d) 06-18-2017 2. What
1. What will be the output of the following Python code?
import datetime
d=datetime.date(2017,06,18)
print(d)
a) Error
b) 2017-06-18
c) 18-06-2017
d) 06-18-2017
2. 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'
3. What is the type of each element in sys.argv?
a) set
b) list
c) tuple
d) string
4. What will be the output of the following Python code?
def f(x):
print("outer")
def f1(a):
print("inner")
print(a,x)
f(3)
f1(1)
a)
outer
error
b)
inner
error
c)
outer
inner
d) error
5. Which of the statements about dictionary values if false?
a) More than one key can have the same value
b) The values of the dictionary can be accessed as dict[key]
c) Values of a dictionary must be unique
d) Values of a dictionary can be a mixture of letters and numbers
6. What is Instantiation in terms of OOP terminology?
a) Deleting an instance of class
b) Modifying an instance of class
c) Copying an instance of class
d) Creating an instance of class
7. In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to ______
a) Zero
b) None
c) One
d) Error
8. Is the following Python code valid?
try:
# Do something
except:
# Do something
finally:
# Do something
a) no, there is no such thing as finally
b) no, finally cannot be used with except
c) no, finally must come before except
d) yes
9. What will be the output of the following Python code?
def maximum(x, y):
if x > y:
return x
elif x == y:
return 'The numbers are equal'
else:
return y
print(maximum(2, 3))
a) 2
b) 3
c) The numbers are equal
d) None of the mentioned
10. What happens if the base condition isn't defined in recursive programs?
a) Program gets into an infinite loop
b) Program runs once
c) Program runs n number of times where n is the argument given to the function
d) An exception is thrown
11. How do you get the current position within the file?
a) fp.seek()
b) fp.tell()
c) fp.loc
d) fp.pos
12. Which of the following functions returns a value in degrees, counterclockwise from the horizontal right?
a) heading()
b) degrees()
c) position()
d) window_height()
13. What will be the output of the following Python code?
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
a) 4
b) 5
c) 1
d) An exception is thrown
14. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
a) 1
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block
15. What will be the output of the following Python function?
divmod(10.5,5)
divmod(2.4,1.2)
a)
(2.00, 0.50)
(2.00, 0.00)
b)
(2, 0.5)
(2, 0)
c)
(2.0, 0.5)
(2.0, 0.0)
d)
(2, 0.5)
(2)
16. Which of the following statements create a dictionary?
a) d = {}
b) d = {"john":40, "peter":45}
c) d = {40:"john", 45:"peter"}
d) All of the mentioned
17. What will be the output of the following Python code?
def power(x, y=2):
r = 1
for i in range(y):
r = r * x
return r
print power(3)
print power(3, 3)
a)
212
32
b)
9
27
c)
567
98
d) None of the mentioned
18. What will be the output of the following Python code?
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)
a) True
b) False
c) None
d) Error
19. What will be the output of the following Python code?
import turtle()
t=turtle.Pen()
t.goto(50,60)
t1=t.clone()
t1.ycor()
a) 0.0
b) 50.0
c) 60.0
d) Error
20. What is unpickling?
a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned
21. The following Python code will result in an error if the input value is entered as -5.
assert False, 'Spanish'
a) True
b) False
22. What will be the output of the following Python code?
class A:
def __repr__(self):
return "1"
class B(A):
def __repr__(self):
return "2"
class C(B):
def __repr__(self):
return "3"
o1 = A()
o2 = B()
o3 = C()
print(obj1, obj2, obj3)
a) 1 1 1
b) 1 2 3
c) '1' '1' '1'
d) An exception is thrown
23. What is a variable defined inside a function referred to as?
a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable
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