We have listed here some multiple choice questions with answer for Python Script, Which has asked by multiple companies like Genpact, Syntel, Ericsson, Zensar, Virtusa etc.

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

1. What type of data is: a=[(1,1),(2,4),(3,9)]?
a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type

Answer: b

2. Is the following piece of code valid?
>>> a,b,c=1,2,3
>>> a,b,c
a) Yes, [1,2,3] is printed
b) No, invalid syntax
c) Yes, (1,2,3) is printed
d) 1 is printed

Answer: c

3. Is the following line of code valid?
>>> a,b=1,2,3
a) Yes, this is an example of tuple unpacking. a=1 and b=2
b) Yes, this is an example of tuple unpacking. a=(1,2) and b=3
c) No, too many values to unpack
d) Yes, this is an example of tuple unpacking. a=1 and b=(2,3)

Answer: c

4. What is the output of the following code?
>>> import collections
>>> a=collections.namedtuple(‘a’,[‘i’,’j’])
>>> obj=a(i=4,j=7)
>>> obj
a) a(i=4, j=7)
b) obj(i=4, j=7)
c) (4,7)
d) An exception is thrown

Answer: a

5. Is the following piece of code valid?
>>> a=2,3,4,5
>>> a
a) Yes, 2 is printed
b) Yes, [2,3,4,5] is printed
c) No, too many values to unpack
d) Yes, (2,3,4,5) is printed

Answer: d

6. What is the output of the following piece of code?
>>> a=[(2,4),(1,2),(3,9)]
>>> a.sort()
>>> a
a) [(1, 2), (2, 4), (3, 9)].
b) [(2,4),(1,2),(3,9)].
c) Error because tuples are immutable
d) Error, tuple has no sort attribute

Answer: d

7. Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
c) set((1,2,3,4))
d) {1,2,3,4}

Answer: a

8. Which of the following statements is used to create an empty set?
a) { }
b) set()
c) [ ].
d) ( )

Answer: b

9. If a={5,6,7,8}, which of the following statements is false?
a) print(len(a))
b) print(min(a))
c) a.remove(5)
d) a[2]=45

Answer: d

10. What is the output of the following code?
>>> s={5,6}
>>> s*3
a) Error as unsupported operand type for set data type
b) {5,6,5,6,5,6}
c) {5,6}
d) Error as multiplication creates duplicate elements which isn’t allowed

Answer: a

11. Which of these about a frozen set is not true?
a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type

Answer: a

12. What is the output of the following piece of code when executed in the python shell?
>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a
a) {2,3}
b) Error, duplicate item present in list
c) Error, no method called intersection_update for set data type
d) {1,4,5}

Answer: a

13. What is the output of the following code?
>>> a={1,2,3}
>>> b=a.add(4)
>>> b
a) None
b) {1,2,3,4}
c) {1,2,3}
d) Nothing is printed

Answer: d

14. What is the output of the following code?
>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}
a) {2,4,6}
b) Error, set comprehensions aren’t allowed
c) {8, 2, 10, 4, 6}
d) {8,10}

Answer: c

15. What is the output of the following piece of code?
a={1,2,3}
b={1,2,3}
c=a.issubset(b)
print(c)
a) True
b) Error, no method called issubset() exists
c) Syntax error for issubset() method
d) False

Answer: a

16. Which of the following lines of code will result in an error?
a) s={abs}
b) s={4, ‘abc’, (1,2)}
c) s={2, 2.2, 3, ‘xyz’}
d) s={think}

Answer: d

17. Write a list comprehension for number and its cube for:
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]

Answer: a

18. What is the output of the snippet of code shown below?
z=set(‘abc$de’)
‘a’ in z
a) True
b) False
c) No output
d) Error

Answer: a

19. The output of the line of code shown below is: class<’set’>. State whether this statement is true or false.
type({})
a) True
b) False

Answer: b

20. The ____________ function removes the first element of a set and the last element of a list.
a) remove
b) pop
c) discard
d) dispose

Answer: b

21. The difference between the functions discard and remove is that:
a) Discard removes the last element of the set whereas remove removes the first element of the set
b) Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element
c) Remove removes the last element of the set whereas discard removes the first element of the set
d) Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element

Answer: d

22. Which of the following is not a declaration of the dictionary?
a) {1: ‘A’, 2: ‘B’}
b) dict([[1,”A”],[2,”B”]])
c) {1,”A”,2”B”}
d) { }

Answer: c

23. 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=” “)
a) 1 A 2 B 3 C
b) 1 2 3
c) A B C
d) 1:”A” 2:”B” 3:”C”

Answer: a

24. What is the output of the following code?
a={1:”A”,2:”B”,3:”C”}
print(a.setdefault(3))
a) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) C
c) {1: 3, 2: 3, 3: 3}
d) No method called setdefault() exists for dictionary

Answer: b

25. What is the output of the following code?
a={1:”A”,2:”B”,3:”C”}
b=a.copy()
b[2]=”D”
print(a)
a) Error, copy() method doesn’t exist for dictionaries
b) {1: ‘A’, 2: ‘B’, 3: ‘C’}
c) {1: ‘A’, 2: ‘D’, 3: ‘C’}
d) “None” is printed

Answer: b