top of page
  • Facebook
  • Twitter
  • Instagram

Top Python Interview Questions

Mobiprep handbooks are free downloadable placement preparation resources that can help you ace any company placement process. We have curated a list of the 40 most important MCQ questions which are asked in most companies such as Infosys, TCS, Wipro, Accenture, etc. The placement handbooks also have detailed explanations for every question ensuring you revise all the questions with detailed answers and explanations.

Question

13

Explanation

Explain shallow copy in python.

When there is a creation of new instance type and it maintains the values, which are copied in the new instance, Shallow copy is utilized.
Like values, Shallow copy is also helpful in copying the reference pointers.

Question

14

Explanation

What is the difference between .py and .pyc files?

1. .py files contain the source code of a program. Whereas, .pyc file contains the bytecode of your program. We get bytecode after compilation of .py file (source code). .pyc files are not created for all the files that you run. It is only created for the files that you import.
2. Before executing a python program python interpreter checks for the compiled files. If the file is present, the virtual machine executes it. If not found, it checks for .py file. If found, compiles it to .pyc file and then python virtual machine executes it.
3. Having .pyc file saves you the compilation time.

Question

15

Explanation

What are decorators in python?

Decorators in Python are essentially functions that add functionality to an existing function in Python without changing the structure of the function itself. They are represented by the @decorator_name in Python and are called in bottom-up fashion.
EXAMPLE:

# decorator function to convert to lowercase
def lowercase_decorator(function):
def wrapper():
func = function()
string_lowercase = func.lower()
return string_lowercase
return wrapper

# decorator function to split words
def splitter_decorator(function):
def wrapper():
func = function()
string_split = func.split()
return string_split
return wrapper

@splitter_decorator # this is executed next
@lowercase_decorator # this is executed first
def hello():
return 'Hello World'

hello() # output => [ 'hello' , 'world' ]

Question

16

Explanation

How memory is managed in Python?

Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap.
The allocation of Python heap space for Python objects is done by Python memory manager. The core API gives access to some tools for the programmer to code. Python also have an inbuilt garbage collector, which recycle all the unused memory andfrees the memory and makes it available to the heap space

bottom of page