0% found this document useful (0 votes)
138 views9 pages

IZETAM TECHNOLOGIES - Interview Questions of Python For 2 Years Experienced

Python is a high-level, interpreted, object-oriented scripting language that is highly readable and compatible across different platforms. It executes code line by line without compilation. Lists are mutable sequences that consume more memory, while tuples are immutable sequences that consume less memory. PEP 8 specifies code style guidelines for readability. Memory is managed privately by Python's garbage collector. PYTHONPATH specifies module file locations. Modules contain reusable code stored in .py files. Namespaces ensure unique names, while scopes define variable lifetimes and accessibility. Dictionaries store elements as key-value pairs. The __init__() method initializes new objects. Common data types include numbers, strings, tuples, lists, dictionaries, and sets. Local variables are accessible within

Uploaded by

Preethi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views9 pages

IZETAM TECHNOLOGIES - Interview Questions of Python For 2 Years Experienced

Python is a high-level, interpreted, object-oriented scripting language that is highly readable and compatible across different platforms. It executes code line by line without compilation. Lists are mutable sequences that consume more memory, while tuples are immutable sequences that consume less memory. PEP 8 specifies code style guidelines for readability. Memory is managed privately by Python's garbage collector. PYTHONPATH specifies module file locations. Modules contain reusable code stored in .py files. Namespaces ensure unique names, while scopes define variable lifetimes and accessibility. Dictionaries store elements as key-value pairs. The __init__() method initializes new objects. Common data types include numbers, strings, tuples, lists, dictionaries, and sets. Local variables are accessible within

Uploaded by

Preethi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

IZETAM TECHNOLOGIES - Interview questions of python for 2 years experienced

1. What is Python?
 Python is a high-level, interpreted, interactive, and object-oriented scripting language. It uses English keywords
frequently. Whereas, other languages use punctuation, Python has fewer syntactic constructions.
 Python is designed to be highly readable and compatible with different platforms such as Mac, Windows, Linux,
Raspberry Pi, etc.

2. Python is an interpreted language. Explain.


An interpreted language is any programming language that executes its statements line by line. Programs written in Python run
directly from the source code, with no intermediary compilation step.

3. What is the difference between lists and tuples?

Lists Tuples
Lists are mutable, i.e., they can be edited Tuples are immutable (they are lists that cannot be edited)
Lists are usually slower than tuples Tuples are faster than lists
Lists consume a lot of memory Tuples consume less memory when compared to lists
Lists are less reliable in terms of errors as Tuples are more reliable as it is hard for any unexpected
unexpected changes are more likely to occur change to occur
Lists consist of many built-in functions. Tuples do not consist of any built-in functions.
Syntax: Syntax:

list_1 = [10, ‘Intellipaat’, 20] tup_1 = (10, ‘Intellipaat’ , 20)

4. What is pep 8?
PEP in Python stands for Python Enhancement Proposal. It is a set of rules that specify how to write and design Python code for
maximum readability.

5. How is memory managed in Python?

Memory in Python is managed by Python private heap space. All Python objects and data structures are located in a private
heap. This private heap is taken care of by Python Interpreter itself, and a programmer doesn’t have access to this private heap.

1. Python memory manager takes care of the allocation of Python private heap space.
2. Memory for Python private heap space is made available by Python’s in-built garbage collector, which recycles and frees
up all the unused memory.

6. What is PYTHONPATH?

PYTHONPATH has a role similar to PATH. This variable tells Python Interpreter where to locate the module files imported into a
program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH
is sometimes preset by Python Installer.

7. What are Python Modules?


Files containing Python codes are referred to as Python Modules. This code can either be classes, functions or variables and
saves the programmer time by providing the predefined functionalities when needed. It is a file with “.py” extension containing an
executable code.

Commonly used built modules are listed below:

 os
 sys
 data time
 math
 random
 JSON

8. What are python namespaces?


A Python namespace ensures that object names in a program are unique and can be used without any conflict.
Python implements these namespaces as dictionaries with ‘name as key’ mapped to its respective ‘object as value’.
Let’s explore some examples of namespaces:

 Local Namespace consists of local names inside a function. It is temporarily created for a function call and gets cleared
once the function returns.
 Global Namespace consists of names from various imported modules/packages that are being used in the ongoing
project. It is created once the package is imported into the script and survives till the execution of the script.
 Built-in Namespace consists of built-in functions of core Python and dedicated built-in names for various types of
exceptions.

9. Explain Inheritance in Python with an example?


As Python follows an object-oriented programming paradigm, classes in Python have the ability to inherit the
properties of another class. This process is known as inheritance. Inheritance provides the code reusability feature.
The class that is being inherited is called a super class or the parent class, and the class that inherits the super class is
called a derived or child class. The following types of inheritance are supported in Python :

 Single inheritance: When a class inherits only one super class


 Multiple inheritance: When a class inherits multiple super classes
 Multilevel inheritance: When a class inherits a super class, and then another class inherits this derived class
forming a ‘parent, child, and grandchild’ class structure
 Hierarchical inheritance: When one super class is inherited by multiple derived classes

10. What is scope resolution?


A scope is a block of code where an object in Python remains relevant. Each and every object of python functions
within its respective scope. As Namespaces uniquely identify all the objects inside a program but these namespaces
also have a scope defined for them where you could use their objects without any prefix. It defines the accessibility
and the lifetime of a variable.
Let’s have a look on scope created as the time of code execution:
 A local scope refers to the local objects included in the current function.
 A global scope refers to the objects that are available throughout execution of the code.
 A module-level scope refers to the global objects that are associated with the current module in the
program.
 An outermost scope refers to all the available built-in names callable in the program.

11. What is a dictionary in Python?


Python dictionary is one of the supported data types in Python. It is an unordered collection of elements. The
elements in dictionaries are stored as key–value pairs. Dictionaries are indexed by keys.

12. What is init in Python?


Equivalent to constructors in OOP terminology, init is a reserved method in Python classes. The init method is called
automatically whenever a new object is initiated. This method allocates memory to the new object as soon as it is
created. This method can also be used to initialize variables.
Output:

Hello, my age is 22

13. What are the common built-in data types in Python?


Python supports the below-mentioned built-in data types:

Immutable data types:

 Number
 String
 Tuple

Mutable data types:

 List
 Dictionary
 set

14. What are local variables and global variables in Python?


Local variable: Any variable declared inside a function is known as Local variable and it’s accessibility remains inside
that function only.
Global Variable: Any variable declared outside the function is known as Global variable and it can be easily
accessible by any function present throughout the program.
Output: 20
If you try to access the local variable outside the multiply function then you will end up with getting an error.

15. What is type conversion in Python?


Python provides you with a much-needed functionality of converting one form of data type into the needed one and
this is known as type conversion.
Type Conversion is classified into types:
 Implicit: Type Conversion: In this form of Type conversion python interpreter helps in automatically
converting the data type into another data type without any User involvement.
 Explicit: Type Conversion: In this form of Type conversion the data type inn changed into a required type by
the user.
 Various Functions of explicit conversion are show below:

16. How to install Python on Windows and set a path variable?


For installing Python on Windows, follow the steps shown below:

 Click on this link for installing the python: Download Python

 After that, install it on your PC by looking for the location where PYTHON has been installed on your PC by
executing the following command on command prompt;

 Visits advanced system settings and after that add a new variable and name it as PYTHON_NAME and paste
the path that has been copied.
 Search for the path variable -> select its value and then select ‘edit’.
 Add a semicolon at the end of the value if it’s not present and then type %PYTHON_HOME%

17. What is the difference between Python Arrays and lists?

List Array
Consists of elements belonging to different data Consists of only those elements having the same
types data type
No need to import a module for list declaration Need to explicitly import a module for array
declaration
Can be nested to have different type of elements Must have all nested elements of the same size
Recommended to use for shorter sequence of data Recommended to use for longer sequence of data
items items
More flexible to allow easy modification (addition or Less flexible since addition or deletion has to be
deletion) of data done element-wise
Consumes large memory for the addition of Comparatively more compact in memory size while
elements inserting elements
Can be printed entirely without using looping A loop has to be defined to print or access the
components
Syntax: Syntax:
list = [1,”Hello”,[‘a’,’e’]] import array
array_demo = array.array(‘i’, [1, 2, 3])
(array  as integer type)

18. Is python case sensitive?


Yes, Python is a case sensitive language. This means that Function and function both are different in python alike SQL and
Pascal.

19. Is indentation required in Python?


Indentation in Python is compulsory and is part of its syntax.
All programming languages have some way of defining the scope and extent of the block of codes. In Python, it is
indentation. Indentation provides better readability to the code, which is probably why Python has made it
compulsory.
20. How does break, continue, and pass work?
These statements help to change the phase of execution from the normal flow that is why they are termed loop
control statements.
Python break: This statement helps terminate the loop or the statement and pass the control to the next statement.
Python continue: This statement helps force the execution of the next iteration when a specific condition meets,
instead of terminating it.
Python pass: This statement helps write the code syntactically and wants to skip the execution. It is also considered
a null operation as nothing happens when you execute the pass statement.

21. How can you randomize the items of a list in place in Python?
This can be easily achieved by using the Shuffle () function from the random 

From random import shuffle

22. How to comment with multiple lines in Python?


To add a multiple lines comment in python, all the line should be prefixed by #.

23. What type of language is python? Programming or scripting?


Generally, Python is an all purpose Programming Language; in addition to that Python is also capable to perform
scripting.
24. What are negative indexes and why are they used?
To access an element from ordered sequences, we simply use the index of the element, which is the position
number of that particular element. The index usually starts from 0, i.e., the first element has index 0, the second has
1, and so on.

25. Explain split (), sub (), subn () methods of “re” module in Python?
These methods belong to the Python Reg Ex or‘re’ module and are used to modify strings.

 Split (): This method is used to split a given string into a list.
 Sub (): This method is used to find a substring where a regex pattern matches, and then it replaces the
matched substring with a different string.
 Sub (): This method is similar to the sub () method, but it returns the new string, along with the number of
replacements.

26. What do you mean by Python literals?


Literals refer to the data which will be provided to a given in a variable or constant.

Literals supported by python are listed below:

String Literals

These literals are formed by enclosing text in the single or double quotes.

For Example:

“Intellipaat”

‘45879’
Numeric Literals

Python numeric literals support three types of literals

Integer: I=10

Float: i=5.2

Complex: 1.73j

Boolean Literals

Boolean literals help to denote Boolean values. It contains either True or False.

x=True

27. What are the generators in python?


Generator refers to the function that returns an iterable set of items.

28. What are python iterators?


These are the certain objects that are easily traversed and iterated when needed.

29. Do we need to declare variables with data types in Python?


No. Python is a dynamically typed language, I.E., Python Interpreter automatically identifies the data type of a
variable based on the type of value assigned to the variable.
30. Is multiple inheritances supported in Python?
Yes, unlike Java, Python provides users with a wide range of support in terms of inheritance and its usage. Multiple
inheritances refer to a scenario where a class is instantiated from more than one individual parent class. This
provides a lot of functionality and advantages to users.
31. Is Python fully object oriented?
Python does follow an object-oriented programming paradigm and has all the basic OOPs concepts such as
inheritance, polymorphism, and more, with the exception of access specifiers. Python doesn’t support strong
encapsulation (adding a private keyword before data members). Although, it has a convention that can be used for
data hiding, i.e., prefixing a data member with two underscores.
32. Explain all file processing modes supported in Python?
Python has various file processing modes.
For opening files, there are three modes:

 read-only mode (r)


 write-only mode (w)
 read–write mode (rw)

For opening a text file using the above modes, we will have to append‘t’ with them as follows:

 read-only mode (rt)


 write-only mode (wt)
 read–write mode (rwt)

Similarly, a binary file can be opened by appending ‘b’ with them as follows:

 read-only mode (rb)


 write-only mode (wb)
 read–write mode (rwb)

To append the content in the files, we can use the append mode (a):

 For text files, the mode would be ‘at’


 For binary files, it would be ‘ab’

33. What do file-related modules in Python do? Can you name some file-related modules in Python?
Python comes with some file-related modules that have functions to manipulate text files and binary files in a file
system. These modules can be used to create text or binary files, update their content, copy, delete, and more.
Some file-related modules are os, os. Path and shuttle. The OS Path module has functions to access the file system,
while the shutil.os module can be used to copy or delete files.

34. what is the purpose of is, not and in operators?


Operators are referred to as special functions that take one or more values (operands) and produce a corresponding
result.

 is: returns the true value when both the operands are true  (Example: “x” is ‘x’)
 Not: returns the inverse of the Boolean value based upon the operands (example:”1” returns “0” and vice-
versa.
 In: helps to check if the element is present in a given Sequence or not.

35. Whenever Python exits, why isn’t all the memory de-allocated?

 Whenever Python exits, especially those Python modules which are having circular references to other
objects or the objects that are referenced from the global namespaces are not always de-allocated or freed.
 It is not possible to de-allocate those portions of memory that are reserved by the C library.
 On exit, because of having its own efficient clean up mechanism, Python would try to de-allocate every
object.

36. How can the ternary operators be used in python?


Ternary operator is the operator that is used to show the conditional statements in Python. This consists of
the Boolean true or false values with a statement that has to be checked.

37. What is Polymorphism in Python?


Polymorphism is the ability of the code to take multiple forms. Let’s say, if the parent class has a method named XYZ then the
child class can also have a method with the same name XYZ having its own variables and parameters.

38. Define encapsulation in Python?


Encapsulation in Python refers to the process of wrapping up the variables and different functions into a single entity
or capsule. Python class is the best example of encapsulation in python.

39. What advantages do NumPy arrays offer over (nested) Python lists?
Nested Lists:

 Python lists are efficient general-purpose containers that support efficient operations like insertion,
appending, deletion and concatenation.
 The limitations of lists are that they don’t support “vectorized” operations like element wise addition and
multiplication, and the fact that they can contain objects of differing types means that Python must store type
information for every element, and must execute type dispatching code when operating on each element.

40. What is self in Python?


Self is an object or an instance of a class. This is explicitly included as the first parameter in Python. On the other
hand, in Java it is optional. It helps differentiate between the methods and attributes of a class with local variables.
The self variable in the init method refers to the newly created object, while in other methods, it refers to the object
whose method was called.
41. How is Multithreading achieved in Python?
 Python has a multi-threading package, but commonly not considered as good practice to use it as it will result
in increased code execution time.
 Python has a constructor called the Global Interpreter Lock (GIL). The GIL ensures that only one of your
‘threads’ can execute at one time. The process makes sure that a thread acquires the GIL, does a little work,
then passes the GIL onto the next thread.
 This happens at a very Quick instance of time and that’s why to the human eye it seems like your threads are
executing parallely, but in reality they are executing one by one by just taking turns using the same CPU core.

42. What is slicing in Python?


Slicing is a process used to select a range of elements from sequence data type like list, string and tuple. Slicing is
beneficial and easy to extract out the elements. It requires a : (colon) which separates the start index and end index
of the field. All the data sequence types List or tuple allows us to use slicing to get the needed elements. Although
we can get elements by specifying an index, we get only a single element whereas using slicing we can get a group or
appropriate range of needed elements.
43. What is monkey patching in Python?
Monkey patching is the term used to denote the modifications that are done to a class or a module during the
runtime. This can only be done as Python supports changes in the behavior of the program while being executed.
44. What is C?
Support vector machine (SVM) is a supervised machine learning model that considers the classification algorithms for two-
group classification problems. Support vector machine is a representation of the training data as points in space are separated
into categories with the help of a clear gap that should be as wide as possible.

45. What is regression?


Regression is termed as supervised machine learning algorithm technique which is used to find the correlation
between variables and help to predict the dependent variable(y) based upon the independent variable (x). It is
mainly used for prediction, time series modeling, forecasting, and determining the causal-effect relationship
between variables.
Scikit library is used in python to implement the regression and all machine learning algorithms.
There are two different types of regression algorithms in machine learning:
Linear Regression: Used when the variables are continuous and numeric in nature.
Logistic Regression: Used when the variables are continuous and categorical in nature.

46. What is pass in Python?

The pass keyword represents a null operation in Python. It is generally used for the purpose of filling up empty
blocks of code which may execute during runtime but has yet to be written. Without the pass statement in the
following code, we may run into some errors during code execution.
47. What is docstring in Python?

 Documentation string or docstring is a multiline string used to document a specific code segment.
 The docstring should describe what the function or method does.

48. What is lambda in Python?


A lambda function is a small anonymous function that can take any number of arguments but can only have one
expression.
x= lambda y: y+20
Print(x (5))

Output
25
Here lambda function adds 20 to the argument and prints the result.

49. What is pickling and unpickling?


Pickling is a process to convert an object into character streams. And unpickling is the inverse of that means
converting character streams into objects.
Pickling is mostly used to save the state of objects and reuse it later without losing any instance-specific data.

50. What is a shallow copy and deep copy in Python?

Shallow copy: - In shallow copy when we copy one object into another object, then whatever we perform any
changes in the second object, it will also reflect into the first object. To perform shallow copy we have “copy ()”
function.
deep copy () :- In a deep copy, when we copy one object into another object, whatever we perform, any
changes in the second object will not reflect into the first object. To perform deep copy we have a “deepcopy ()”
function.

You might also like