Python interview questions part 21

Python interview questions part 21

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What is the output of the following code? i=0 def change(i): i=i+1 return i change(1) print(i)

Correct Answer is : 0

2. What is the output of the following piece of code? def a(b): b = b + [5]   c = [1, 2, 3, 4] a(c) print(len(c))

Correct Answer is : 5

3. What is the output of the following code? a=10 b=20 def change(): global b a=45 b=56 change() print(a) print(b)

Correct Answer is : 10

4. What is the output of the following code? def change(i = 1, j = 2): i = i + j j = j + 1 print(i, j) change(j = 1, i = 2)

Correct Answer is : 45353

5. What is the output of the following code? def change(one, *two): print(type(two)) change(1,2,3,4)

Correct Answer is : Tuple

6. If a function doesn’t have a return statement, which of the following does the function return?

Correct Answer is : None

7. What is the output of the following code? def display(b, n): while n > 0: print(b,end="") n=n-1 display('z',3)

Correct Answer is : zzz

8. What is the output of the following piece of code? def find(a, **b): print(type(b)) find('letters',A='1',B='2')

Correct Answer is : Dictionary

9. The output of the code shown below is: odd=lambda x: bool(x%2) numbers=[n for n in range(10)] print(numbers) n=list() for i in numbers: if odd(i): continue else: break

Correct Answer is : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

10. What is the output of the code shown below? f=lambda x:bool(x%2) print(f(20), f(21))

Correct Answer is : False True

11. What is the output of the code shown below? import functools l=[1,2,3,4] print(functools.reduce(lambda x,y:x*y,l))

Correct Answer is : 24

12. What is the output of the code shown? l=[1, -2, -3, 4, 5] def f1(x): return x<2 m1=filter(f1, l) print(list(m1))

Correct Answer is : [1, -2, -3]

13. What is the output of the code shown below? l=[-2, 4] m=map(lambda x:x*2, l) print(m)

Correct Answer is : Address of m

14. What is the output of the following code? l=[1, -2, -3, 4, 5] def f1(x): return x<-1 m1=map(f1, l) print(list(m1))

Correct Answer is : [False, True, True, False, False]

15. What is the output of the code shown? l=[1, 2, 3, 4, 5] m=map(lambda x:2**x, l) print(list(m))

Correct Answer is : [2, 4, 8, 16, 32 ]

16. What is the output of the code shown? import functools l=[1, 2, 3, 4, 5] m=functools.reduce(lambda x, y:x if x>y else y, l) print(m)

Correct Answer is : 5

17. What is the output of the code shown below? l=[n for n in range(5)] f=lambda x:bool(x%2) print(f(3), f(1)) for i in range(len(l)): if f(l[i]): del l[i] print(i)

Correct Answer is : True True

18. What is the output of the code shown? m=reduce(lambda x: x-3 in range(4, 10)) print(list(m))

Correct Answer is : No output

19. Which of the following numbers will not be a part of the output list of the code shown below? def sf(a): return a%3!=0 and a%5!=0 m=filter(sf, range(1, 31)) print(list(m))

Correct Answer is : 10

20. The single line equivalent of the code shown below is: l=[1, 2, 3, 4, 5] def f1(x): return x<0 m1=filter(f1, l) print(list(m1))

Correct Answer is : filter(lambda x:x<0, l)

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon