Python Interview Questions
Python Interview Questions
Each Python program file is a module that imports other modules like
objects. The folder of a Python programs is called a package of
modules.
A namespace is a system that has a unique name for each and every
object in Python. An object might be a variable or a method
Interpreted
Dynamically-typed
Object-oriented
English-like syntax
10) What are python modules? Name some commonly used built-in
modules in Python?
Python modules are files containing Python code that can be either
function classes or variables.
os
sys
math
random
data time
JSON
In python both arrays and lists are used to store data , main difference is
arrays can store of same data type but list can store any type of datatype
Break :Break is used to terminate the loop when specific condition met.
Continue: It is used to terminate the current loop and skip the code of
current loop and continue to next loop
Pass:
o Python also has an inbuilt garbage collector, which recycle all the
unused memory and frees the memory for the heap space.
Xrange returns the xrange object while range returns the list, and uses
the same memory and no matter what the range size
is.However, xrange() is used only in Python 2. x whereas range() is used
in Python 3. x.
Python version : 3.6 to 3.8 we used in our project and latest version is
3.9.2
List comprehensions are used for transforming on list into another list.
Or
Using the list,we need to create another list by applying some filters or
manipulation
Syntax: output = [ <expression> for <variable> in <Reference>]
for ex: list = [i for i in range(1000)]
Print(list)
All the properties and attributes of one class derived or used in another
class is called inheritance.
It provides the re-usability of the code.
1. single inheritance
2. Multilevel inheritance - one parent has multiple childs
3. Multiple inheritance - one child has multiple parents
Import os
The ability of a system to support more than one processor at the same
time.Applications in a multiprocessing system are broken to smaller
routines that run independently. The operating system allocates these
threads to the processors improving performance of the system.
The self is used to represent the instance of the class. With this keyword,
you can access the attributes and methods of the class in python
Import reportlab
or
Import xhtml2pdf and pisa
The value of variable is varied from object to object ,then such type of
variable is called instance variable.
For every object a separate copy of instance variable will be
created.
Where we can declare instance variable
A. inside constructor by using self variable
B. Inside instance method by using self variable
C. Outside of the class by using object reference variable
The value of variable not varies from object to object then such type of
variable is called static variab le or class variable
For total class only one copy of static variable will be created and shared
by all objects of that class.
We can access static variable either class name or by object reference
Where we can declare static or class variable
a. we can declare inside the class
b. Inside constructor by using class name
c. inside instance method by using class name
d. Inside method by using class name or cls variable I,e @class method
e. Inside static method by using class name
Inside method ,if we are using any class variable or static variable then
such type of method we call as class method
We can declare class method explicitly by using @class method
decorator
For class method we should provide class variable at the time of
declaration
We can call class method by using class name or object reference
variable
Static method belongs to the class.It is just like a static variable that
bounds to the class rather than the class's object. A static method can be
called without creating an object for the class. It means we can directly
call the static method with the reference of the class name.
(or)
A static method is a method which is bound to the class and not the
object of the class. It can't access or modify class state. It is present in a
class because it makes sense for the method to be present in class.
A static method does not receive an implicit first argument.
48) What are *args and **kwargs ?