Python Interview Questions


We have selected the most asked python interview questions and the way to answer them. Prepare Now!

category

Most asked question in the interview regarding Python Interview Questions

Ques. ) What type of language is python? Programming or scripting?


Answer:

Python is capable of scripting, but in a general sense, it is considered as a general-purpose programming language.

Ques. ) How is Python an interpreted language?


Answer:

An interpreted language is any programming language that is not in machine-level code before runtime. Therefore, Python is an interpreted language.

Ques. ) What is namespace in Python?


Answer:

A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.

Ques. ) What is PYTHONPATH?


Answer:

It is an environment variable that is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.

Ques. ) How is memory managed in Python?


Answer:

1. Memory management in python is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have access to this private heap. The python interpreter takes care of this instead. 2. The allocation of heap space for Python objects is done by Python’s memory manager. The core API gives access to some tools for the programmer to code. 3. Python also has an inbuilt garbage collector, which recycles all the unused memory and so that it can be made available to the heap space.

Ques. ) What are python modules? Name some commonly used built-in modules in Python?


Answer:

Python modules are files containing Python code. This code can either be functions, classes, or variables. A Python module is a .py file containing executable code. Some of the commonly used built-in modules are: 1. os 2. sys 3. math 4. random

Ques. ) What are local variables and global variables in Python?


Answer:

Global Variables: Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program. Local Variables: Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.

Ques. ) What is type conversion in Python?


Answer:

Type conversion refers to the conversion of one data type into another. int() – converts any data type into integer type float() – converts any data type into float type ord() – converts characters into integer hex() – converts integers to hexadecimal oct() – converts integer to octal

Ques. ) What is __init__?


Answer:

__init__ is a method or constructor in Python. This method is automatically called to allocate memory when a new object/ instance of a class is created. All classes have the __init__ method.

Ques. ) What is a lambda function?


Answer:

An anonymous function is known as a lambda function. This function can have any number of parameters but can have just one statement.

Ques. ) What does [::-1} do?


Answer:

[::-1] is used to reverse the order of an array or a sequence. 1 import array as arr My_Array=arr.array('i',[1,2,3,4,5]) 2 My_Array[::-1] 3 Output: array(‘i’, [5, 4, 3, 2, 1])

Ques. ) How can you randomize the items of a list in place in Python?


Answer:

Below is a code for question -: from random import shuffle x = ['Keep', 'The', 'Blue', 'Flag', 'Flying', 'High'] shuffle(x) print(x)

Most recent interview's QNA


category-image
c/c++ Interview Question
Get QNA
category-image
Python Interview Questions
Get QNA
category-image
Machine Learning Q/A
Get QNA
More