Here’re the python interview questions asked in Capgemini. The questions are a little tricky but not complex.
Python interview questions
#1. Can we give duplicate keys in the dictionary? and what’s the output for the below scenario?
As a rule, duplicate keys are not allowed. The result of the below scenario is the value will be the last one.
Scenario:
dict= {“a”: 1, “b”:2, “a”:5}
print(dict[“a”])
Output
5
** Process exited – Return Code: 0 **
Press Enter to exit terminal
#2. How to merge three lists in python?
You can resolve it by using the ZIP method.
Scenario:
a=[1,2,3]
b=[3,4,5]
c=[6,7,8]
new_list=zip(a,b,c)
print(list(new_list))
Output
[(1, 3, 6), (2, 4, 7), (3, 5, 8)]
** Process exited – Return Code: 0 **
Press Enter to exit terminal
#3. How to print even numbers ( 1 to 100) using the python lambda function?
Scenario:
even = lambda x : x*2
for a in range(1,100):
if (even(a) <=100 ):
print(even(a))
Output
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
** Process exited – Return Code: 0 **
Press Enter to exit terminal
#4. Why tuple is faster than a list?
Since a tuple is immutable and stored in a single memory block. So tuple is faster than a list.
#5. What is memory management in python?
- The garbage collector automatically releases unused objects in one way. The other way is it follows dynamic memory allocation.
- Memory management in Python involves a private heap containing all Python objects and data structures. The Python memory manager has different components which deal with various dynamic storage management aspects, like sharing, segmentation, preallocation, or caching.
- The management of the Python heap is performed by the interpreter itself and the user has no control over it.
#6. What are the popular packages and frameworks in python?
- NumPy
- Pandas
- SciPy
- Django
- Flask
#7. How python works?
Python is an interpreted language. No need to compile. It works interactively. The syntax is elegant and easy, and simple to use.