We have listed here some multiple choice questions with answer for Python Script, Which has asked by multiple companies like CTS, CSC, Dell, Polaris, Patni, Motorola etc.

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

1. Execute the following in Python shell?
>>> a={1:”A”,2:”B”,3:”C”}
>>> a.items()
a) Syntax error
b) dict_items([(‘A’), (‘B’), (‘C’)])
c) dict_items([(1,2,3)])
d) dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

Answer: d

2. If a is a dictionary with some key-value pairs, what does a.popitem() do?
a) Removes an arbitrary element
b) Removes all the key-value pairs
c) Removes the key-value pair for the key given as an argument
d) Invalid method for dictionary

Answer: a

3. What is the output of the following snippet of code?
test = {1:’A’, 2:’B’, 3:’C’}
test = {}
print(len(test))
a) 0
b) None
c) 3
d) An exception is thrown

Answer: a

4. What is the output of the following snippet of code?
a={}
a[‘a’]=1
a[‘b’]=[2,3,4]
print(a)
a) Exception is thrown
b) {‘b’: [2], ‘a’: 1}
c) {‘b’: [2], ‘a’: [3]}
d) {‘b’: [2, 3, 4], ‘a’: 1}

Answer: d

5. What is the output of the following piece of code?
>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)
a) Counter({4: 3, 2: 2, 3: 1})
b) {3:1}
c) {4:3}
d) [(4, 3)].

Answer: d

6. What is the output of the following code?
a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])
a) [2,3,4].
b) 3
c) 2
d) An exception is thrown

Answer: b

7. What is the output of the following snippet of code?
>>> a={i: i*i for i in range(6)}
>>> a
a) Dictionary comprehension doesn’t exist
b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}
c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}
d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Answer: d

8. What is the output of the following snippet of code?
>>> b={}
>>> all(b)
a) { }
b) False
c) True
d) An exception is thrown

Answer: c

9. What is the output of the following piece of code when executed in Python shell?
>>> a={i: ‘A’ + str(i) for i in range(5)}
>>> a
a) An exception is thrown
b) {0: ‘A0’, 1: ‘A1’, 2: ‘A2’, 3: ‘A3’, 4: ‘A4’}
c) {0: ‘A’, 1: ‘A’, 2: ‘A’, 3: ‘A’, 4: ‘A’}
d) {0: ‘0’, 1: ‘1’, 2: ‘2’, 3: ‘3’, 4: ‘4’}

Answer: d

10. What is the output of the following piece of code when executed in Python shell?
>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(str)
>>> a[‘A’]
a) An exception is thrown since the dictionary is empty
b) ‘ ‘
c) ‘A’
d) 0

Answer: b

11. Which of the following functions is a built-in function in python?
a) seed()
b) sqrt()
c) factorial()
d) print()

Answer: d

12. What is the output of the function shown below?
all([2,4,0,6])
a) Error
b) True
c) False
c) 0

Answer: c

13. What is the output of the function shown below?
all([2,4,0,6])
a) Error
b) True
c) False
c) 0

Answer: c

14. What is the output of the function shown below?
import math
abs(math.sqrt(25))
a) Error
b) -5
c) 5
d) 5.0

Answer: d

15. What is the output of the function:
all(3,0,4.2)
a) True
b) False
c) Error
d) 0

Answer: c

16. What is the output of the following function?
complex(1+2j)
a) Error
b) 1
c) 2j
d) 1+2j

Answer: d

17. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
a) (a%b, a//b)
b) (a//b, a%b)
c) (a//b, a*b)
c) (a/b, a%b)

Answer: b

18. What is the output of the function shown below?
list(enumerate([2, 3]))
a) Error
b) [(1, 2), (2, 3)]
c) [(0, 2), (1, 3)]
d) [(2, 3)]

Answer: c

19. What are the outcomes of the function shown below?
x=3
eval(‘x^2’)
a) Error
b) 1
c) 9
d) 6

Answer: b

20. Which of the following functions accepts only integers as arguments?
a) ord()
b) min()
c) chr()
d) any()

Answer: c

21. Which of the following functions will not result in an error when no arguments are passed to it?
a) min()
b) divmod()
c) all()
d) float()

Answer: d

22. Which of the following functions does not throw an error?
a) ord()
b) ord(‘ ‘)
c) ord(”)
d) ord(“”)

Answer: b

23. Which of the following is the use of function in python?
a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity for your application
c) you can’t also create your own functions
d) All of the mentioned

Answer: a

24. Which keyword is use for function?
a) Fun
b) Define
c) Def
d) Function

Answer: c

25. Which are the advantages of functions in python?
a) Reducing duplication of code
b) Decomposing complex problems into simpler pieces
c) Improving clarity of the code
d) All of the mentioned

Answer: d