1. What is the output of the line of code shown below?
list(map((lambda x:x^2), range(10)))
Correct Answer is : [2, 3, 0, 1, 6, 7, 4, 5, 10, 11]
2. What is the output of the line of code shown below?
list(map((lambda x:x**2), filter((lambda x:x%2==0), range(10))))
Correct Answer is : [0, 4, 16, 36, 64]
3. The output of the two codes shown below is the same. State whether true or false.
[x**2 for x in range(10)]
list(map((lambda x:x**2), range(10)))
4. The output of the code shown below is:
def f1():
x=15
print(x)
x=12
f1()
5. What is the output of the code shown below?
def f1():
x=100
print(x)
x=+1
f1()
6. What is the output of the code shown below?
def san(x):
print(x+1)
x=-2
x=4
san(12)
7. What is the output of the code shown?
def f1():
global x
x+=1
print(x)
x=12
print("x")
8. What is the output of the code shown below?
def f1(x):
global x
x+=1
print(x)
f1(15)
print("hello")
Correct Answer is : error
9. What is the output of the following code?
x=12
def f1(a,b=x):
print(a,b)
x=15
f1(4)
Correct Answer is : 45394
10. What is the output of the code shown?
def f():
global a
print(a)
a = "hello"
print(a)
a = "world"
f()
print(a)
Correct Answer is : world
11. What is the output of the code shown below?
def f1(a,b=[]):
b.append(a)
return b
print(f1(2,[3,4]))
Correct Answer is : [3,4,2]
12. What is the output of the code shown below?
def f(p, q, r):
global s
p = 10
q = 20
r = 30
s = 40
print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)
Correct Answer is : 10 20 30 40
13. What is the output of the code shown below?
def f(x):
print("outer")
def f1(a):
print("inner")
print(a,x)
f(3)
f1(1)
Correct Answer is : outer
14. The output of code shown below is:
x = 5
def f1():
global x
x = 4
def f2(a,b):
global x
return a+b+x
f1()
total = f2(1,2)
print(total)
15. What is the output of the code shown below?
x=100
def f1():
global x
x=90
def f2():
global x
x=80
print(x)
16. Read the code shown below carefully and point out the global variables:
y, z = 1, 2
def f():
global x
x = y+z
Correct Answer is : x, y and z
17. Which of the following data structures is returned by the functions globals() and locals()?
Correct Answer is : dictionary
18. What is the output of the code shown below?
x=1
def cg():
global x
x=x+1
cg()
x
19. On assigning a value to a variable inside a function, it automatically becomes a global variable. State whether true or false.
Correct Answer is : FALSE
20. What is the output of the code shown below?
e="butter"
def f(a): print(a)+e
f("bitter")
Correct Answer is : bitter