We have listed here some multiple choice questions with answer for Python Script, Which has asked by multiple companies like ABB, Aditi, BSNL, Integra, Lifetree, L & T Infotech etc.

You can prepare your job written and interview by using these sets of question fro here.

1. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
a) Error
b) None
c) 25
d) 2

Answer: c

2. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is :
a) [0, 1, 2, 3].
b) [0, 1, 2, 3, 4].
c) [0.0, 0.5, 1.0, 1.5].
d) [0.0, 0.5, 1.0, 1.5, 2.0].

Answer: c

3. What is the output when following code is executed ?
>>>list1 = [11, 2, 23]
>>>list2 = [11, 2, 2]
>>>list1 < list2 is
a) True
b) False
c) Error
d) None

Answer: b

4. To add a new element to a list we use which command ?
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)

Answer: b

5. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?
a) 0
b) 1
c) 4
d) 2

Answer: d

6. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1) ?
a) [3, 4, 5, 20, 5, 25, 1, 3].
b) [1, 3, 3, 4, 5, 5, 20, 25].
c) [3, 5, 20, 5, 25, 1, 3].
d) [1, 3, 4, 5, 20, 5, 25].

Answer: c

7. What is the output when the following code is executed ?
>>>”Welcome to Python”.split()
a) [“Welcome”, “to”, “Python”].
b) (“Welcome”, “to”, “Python”)
c) {“Welcome”, “to”, “Python”}
d) “Welcome”, “to”, “Python”

Answer: a

8. What is the output when following code is executed ?
>>>list1 = [1, 3]
>>>list2 = list1
>>>list1[0] = 4
>>>print(list2)
a) [1, 3].
b) [4, 3].
c) [1, 4].
d) [1, 3, 4].

Answer: b

9. How many elements are in m?
m = [[x, y] for x in range(0, 4) for y in range(0, 4)]
a) 8
b) 12
c) 16
d) 32

Answer: c

10. What will be the output?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

print(data[1][0][0])
a) 1
b) 2
c) 4
d) 5

Answer: d

11. What is the output of the following code?
a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in range(0,len(a))]
print(b)
a) 10
b) [1,3,5,7].
c) 4
d) [1,3,6,10].

Answer: d

12. What is the output of the following code?
lst=[3,4,6,1,2]
lst[1:2]=[7,8]
print(lst)
a) [3, 7, 8, 6, 1, 2].
b) Syntax error
c) [3,[7,8],6,1,2].
d) [3,4,6,7,8].

Answer: a

13. What is the output of the following code?
a=165
b=sum(list(map(int,str(a))))
print(b)
a) 561
b) 5
c) 12
d) Syntax error

Answer: c

14. What is the output of the following?
x = [i**+1 for i in range(3)]; print(x);
a) [0, 1, 2].
b) [1, 2, 5].
c) error, **+ is not a valid operator
d) error, ‘;’ is not allowed

Answer: a

15. Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))?
a) [x**-1 for x in [(1, 2, 3)]].
b) [1/x for x in [(1, 2, 3)]].
c) [1/x for x in (1, 2, 3)].
d) error

Answer: c

16. What is the output of the code shown?
s=[“pune”, “mumbai”, “delhi”]
[(w.upper(), len(w)) for w in s]
a) Error
b) [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]
c) [PUNE, 4, MUMBAI, 6, DELHI, 5]
d) [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]

Answer: d

17. What is the output of the code shown below?
import math
[str(round(math.pi)) for i in range (1, 6)]
a) [‘3’, ‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
b) [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’, ‘3.141582’]
c) [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
d) [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’]

Answer: c

18. Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.
a) [x in range(1, 1000) if x%3==0]
b) [x for x in range(1000) if x%3==0]
c) [x%3 for x in range(1, 1000)]
d) [x%3=0 for x in range(1, 1000)]

Answer: b

19. Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].
a) [(2**x) for x in range(0, 13)]
b) [(x**2) for x in range(1, 13)]
c) [(2**x) for x in range(1, 13)]
d) [(x**2) for x in range(0, 13)]

Answer: a

20. Suppose t = (1, 2, 4, 3), which of the following is incorrect?
a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))

Answer: b

21. What will be the output?
>>>t=(1,2,4,3)
>>>t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)

Answer: c

22. What will be the output?
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
a) [2, 3, 9].
b) [1, 2, 4, 3, 8, 9].
c) [1, 4, 8].
d) (1, 4, 8)

Answer: c

23. What will be the output?
d = {“john”:40, “peter”:45}
d[“john”]
a) 40
b) 45
c) “john”
d) “peter”

Answer: a

24. If a=(1,2,3,4), a[1:-1] is
a) Error, tuple slicing doesn’t exist
b) [2,3].
c) (2,3,4)
d) (2,3)

Answer: d

25. What is the output of the following code?
>>> a=(1,2,(4,5))
>>> b=(1,2,(3,4))
>>> a<b
a) False
b) True
c) Error, < operator is not valid for tuples
d) Error, < operator is valid for tuples but not if there are sub-tuples

Answer: a