Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What is the output of the code shown below?
class A:
@staticmethod
def a(x):
print(x)
A.a(100)
Correct Answer is : 100
2. What is the output of the code shown below?
def d(f):
def n(*args):
return '$' + str(f(*args))
return n
@d
def p(a, t):
return a + a*t
print(p(100,0))
Correct Answer is : 100
3. What is the output of the code shown below?
def c(f):
def inner(*args, **kargs):
inner.co += 1
return f(*args, **kargs)
inner.co = 0
return inner
@c
def fnc():
pass
if __name__ == '__main__':
fnc()
fnc()
fnc()
print(fnc.co)
Correct Answer is : 3
4. Which of the following statements create a dictionary?
Correct Answer is : All of the mentioned
5. Read the code shown below carefully and pick out the keys?
d = {"john":40, "peter":45}
Correct Answer is : “john” and “peter”
6. What will be the output?
d = {"john":40, "peter":45}"john" in d
Correct Answer is : TRUE
7. What will be the output?
d1 = {"john":40, "peter":45}d2 = {"john":466, "peter":45}d1 == d2
Correct Answer is : FALSE
8. What will be the output?
d1 = {"john":40, "peter":45}d2 = {"john":466, "peter":45}d1 > d2
Correct Answer is : Error
9. What is the output?
d = {"john":40, "peter":45}d["john"]
Correct Answer is : 40
10. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use
Correct Answer is : del d[“john”].
11. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?
Correct Answer is : len(d)
12. What will be the output?
d = {"john":40, "peter":45}print(list(d.keys()))
Correct Answer is : [“john”, “peter”].
13. Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?
Correct Answer is : Since “susan” is not a key in the set, Python raises a KeyError exception
14. Which of these about a dictionary is false?
Correct Answer is : The keys of a dictionary can be accessed using values
15. Which of the following is not a declaration of the dictionary?
Correct Answer is : {1,”A”,2”B”}
16. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")
Correct Answer is : 1 A 2 B 3 C
17. What is the output of the following piece of code?
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
Correct Answer is : A
18. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
print(a.get(5,4))
Correct Answer is : 4
19. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
print(a.setdefault(3))
Correct Answer is : C
20. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)