python
20 PYTHON INTERVIEW
QUESTIONS AND
ANSWERS
= Rohit Gupta
& Rohit Gup1. What is Pythonpath?
® A Pythonpath tells the Python
interpreter to locate the module
files that can be imported into
the program. It includes the
Python source library directory
and source code directory. You
can preset Pythonpath as a
Python installer.
e Rohit Gupta
Yep2. What are tuples?
® Tuples are a sequence data
type with immutable values in
Python. The number of values i
tuples is separated by commas.
3. What is pep 8?
® Python Enhancement
Proposal or pep 8 is a set of
les that specify how to format
Python code for maximum
readability.
e Rohit Gupta
Yep4. What is namespace in Python?
® A namespace is a naming system
used to make sure names are
unique to avoid naming conflicts
5. Is indentation necessary in
Python?
® Indentation is required in Python
if not done properly the code is not
executed properly and might throw
errors. Indentation is usually done
using four space characters.
e Rohit Gupta
Yep6. What are the limitations of
Python?
® There are limitations to
Python, which include the
following:
It has design restrictions.
It is slower when compared with
C and C++ or Java.
It is inefficient for mobile
computing.
It consists of an
underdeveloped database
access layer.
e Rohit Gupta
Yep7. Why do we need a break?
® Break helps control the Python loop by
breaking the current loop from execution and
transferring the control to the next block.
8. Why do we need a continue?
® Acontinue helps control the Python loop by
making jumps to the next iteration of the loop
without exhausting it.
9. Define slicing in Python.
® Slicing refers to the mechanism to select the
range of items from sequence types like lists,
tuples, strings.
10. What is docstring?
® Docstring is a Python documentation string, it
is a way of documenting Python functions,
classes, and modules.11. What are Python decorators?
® A specific change made in Python syntax to
alter the functions easily are termed as Python
decorators.
12. Differentiate between list and tuple.
® Tuple is not mutable it can be hashed eg. key
for dictionaries. On the other hand, lists are
mutable.
13. What are functions in Python?
® A function is a block of code which is executed
only when a call is made to the function. def
keyword is used to define a particular function as
shown below:
def function():
print("Hi, Welcome to nubcoder")
function(); # call to the function14. Is python case sensitive?
® Yes, Python is a case sensitive language. This
means that Function and function both are
different in pythons like SQL and Pascal.
15. What does [::-1] do?
® [::-1] ,this is an example of slice notation and
helps to reverse the sequence with the help of
indexing.
[Start,stop,step count]
import array as arr
Array_d=arr.array(‘i',[1,2,3,4,5])
Array_d[::-1] #reverse the array or sequence16. What is __init_?
® _init_is acontructor method in Python and
is automatically called to allocate memory when
a new object/instance is created. All classes have
a __init_ method associated with them. It helps
in distinguishing methods and attributes of a
class from local variables.
17. What is the difference between Python Arrays
and lists?
® Arrays in python can only contain elements of
same data types i.e., data type of array should be
homogeneous. It is a thin wrapper around C
language arrays and consumes far less memory
than lists.
Lists in python can contain elements of different
data types i.e., data type of lists can be
heterogeneous. It has the disadvantage of
consuming large memory.18. What is Shallow copy ?
® Shallow Copy is a bit-wise copy of an object.
The copied object created has an exact copy of
the values in the original object. If either of the
values is a reference to other objects, just the
reference addresses for the same are copied.
19. How are arguments passed by value or
by reference in python?
® Pass by value: Copy of the actual object is
passed. Changing the value of the copy of
the object will not change the value of the
original object.
® Pass by reference: Reference to the
actual object is passed. Changing the value
of the new object will change the value of
the original object.20. Are access specifiers used in python?
® Python does not make use of access specifiers
specifically like private, public, protected, etc.
However, it does not derive this from any
variables. It has the concept of imitating the
behaviour of variables by making use of a single
(protected) or double underscore (private) as
prefixed to the variable names. By default, the
variables without prefixed underscores are
public.
\
>
= Rohit Gupta
Wain)FOLOW ME FOR DAILY CONTENT
ON PROGRAMMING
@nubcoder
Rohit Gupta