We have selected the most asked python interview questions and the way to answer them. Prepare Now!
Most asked question in the interview regarding Python Interview Questions
Ques. ) What type of language is python? Programming or scripting?
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?
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?
A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.
Ques. ) What is PYTHONPATH?
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?
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?
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:
Ques. ) What are local variables and global variables in Python?
Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program.
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?
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__?
__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?
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?
[::-1] is used to reverse the order of an array or a sequence.
1 import array as arr
3 Output: array(‘i’, [5, 4, 3, 2, 1])
Ques. ) How can you randomize the items of a list in place in Python?
Below is a code for question -:
from random import shuffle
x = ['Keep', 'The', 'Blue', 'Flag', 'Flying', 'High']