Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Python

Sample Interview Questions:

1. What is the difference between a list and a tuple?

2. What is the difference between an array and a list?

3. What is pickling and unpickling?


Pickle module accepts any Python object and converts it into a string representation and dumps
it into a file by using dump function, this process is called pickling. While the process of
retrieving original Python objects from the stored string representation is called unpickling

4. How is memory management performed in Python?


Python makes use of a Python memory manager to ensure that the memory management is
handled efficiently. The memory will be allocated by the manager which is represented in the
form of private heap space that is only possible in Python. the Python objects will be stored which
are privately secured and are inaccessible to the programmer. Apart from this, Python also
includes a built-in garbage collection which helps in recycling the unused memory for the private
heap space

5. What is the Lambda function in Python?


The Lambda function is referred to as an anonymous function that can have any number of
parameters but only includes one statement.

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.

9. What is meant by a dictionary in Python?

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.

10. What's a negative index?

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.

11. What Are *args and **kwargs?

*args

It is used in a function prototype to accept a varying number of arguments.


It's an iterable object.
Usage - def fun(*args)

*kwargs

It is used in a function prototype to accept the varying number of keyworded arguments.


It's an iterable object
Usage - def fun(**kwargs)

12. What are mutable and immutable data types?

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.

Lambda functions come in handy when there is a single expression.

14. What is a map() function in Python?

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.

15. What is the difference between tuple and dictionary?

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.

16. Explain split() and join() functions in Python?

split() function - to split a string based on a delimiter to a list of strings.


join() function - to join a list of strings based on a delimiter to give a single string.

17. What do you understand by reindexing in pandas?


Reindexing is the process of conforming a dataframe to a new index with optional filling logic. If
the values are missing in the previous index, then NaN/NA is placed in the location. A new object
is returned unless a new index is produced that is equivalent to the current one. The copy value
is set to False. This is also used for changing the index of rows and columns in the dataframe.

18. What is zip() function in Python?


Python zip() function returns a zip object, which maps a similar index of multiple containers. It
takes an iterable, convert into iterator and aggregates the elements based on iterables passed.
It returns an iterator of tuples.

19. What is self in Python?

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.

You might also like