Professional Documents
Culture Documents
Python: Sample Interview Questions
Python: Sample Interview Questions
1
Proprietary content. © 2013 - 2021 Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
6. Explain the differences between the functions remove() and del statement?
The remove() function is specifically used to delete the specific object in the list. You can use the
del or pop function or statement to delete the object based on the index that consists of the
specific location in the list.
7. Briefly describe lists and tuples? Also, explain the main difference between them?
Lists and tuples in Python are referred to as the sequence data types that are capable of storing
the collection of the objects in Python. The objects that are stored can have different data types.
The lists are usually represented in square brackets. Example: list1 =[‘kavya’, 1, 2, 0.34]. The
tuples are usually represented within parentheses. Example : tuple = (‘Kavya’, 1, 2, 0.34). The
primary difference between the lists and tuples is that the lists are mutable while the tuples are
immutable. The lists can be modified while the tuples will remain constant always.
8. Can you explain how to break, continue and pass work in Python?
Break: Whenever the condition is met, the break is responsible for terminating the loop, and also
ensures that the control is transferred to the next statement.
Continue: Whenever the condition is met, the continue is used to ensure that some part of the
loop is skipped and also ensures that the control is transferred to the beginning of the loop.
Pass: Pass is used whenever you are in need of some part of the code and would not like to
perform the execution. It is usually referred to as the null operation and there will not be any
changes when the pass is executed.
The dictionary in Python is the repository of the built-in datatypes. It defines the relationships
that exist between the keys and values. The dictionaries consist of the keys and their
corresponding values and are indexed by the keys.
Python programming language supports negative indexing of arrays, something which is not
available in arrays in most other programming languages. This means that the index value of -1
2
Proprietary content. © 2013 - 2021 Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
gives the last element, and -2 gives the second last element of an array. The negative indexing
starts from where the array ends.
*args
*kwargs
Mutable data types can be changed after creating them. Some of the mutable objects in Python
are list, set, dict.
Immutable data types can’t be changed after creating them. Some of the immutable objects in
Python are str, tuple.
13. What’s the difference between normal function and lambda function?
The functionality of both normal functions and lambda functions are similar. But, we need to
write some extra code in normal functions compared to lambda functions for the same
functionality.
The map() function in Python is used for applying a function on all elements of a specified iterable.
It consists of two parameters, function and iterable. The function is taken as an argument and
3
Proprietary content. © 2013 - 2021 Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
then applied to all the elements of an iterable(passed as the second argument). An object list is
returned as a result.
One major difference between a tuple and a dictionary is that dictionary is mutable while a tuple
is not. Meaning the content of a dictionary can be changed without changing it’s identity, but in
tuple that’s not possible.
Self is an instance or an object of a class. In Python, this is explicitly included as the first
parameter. However, this is not the case in Java where it's optional. It helps to differentiate
between the methods and attributes of a class with local variables.
The self-variable in the init method refers to the newly created object while in other methods, it
refers to the object whose method was called.
4
Proprietary content. © 2013 - 2021 Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.