PYTHON
INTERVIEW QUESTIONS
Top Most Important Python Interview Questions & Answers
PREPARED BY WORKING PROFESSIONAL
1000+ DOWNLOADS
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 1
[Link] is Python?
Answer:
ECH
It is powerful, general purpose, high level, object oriented programming language.
It’s developed by Guido Van Rossum in 1991..
2. Why we use Python?
Answer:
It is very simple and easy to learn.
It powerful, fast and secure.
It has very simple syntax.
It is powerful scripting language.
It can be run on different kind of platform like Windows , Mac, Linux, etc.,
[Link] are the applications developed using Python?
Answer:
Web Application
Software Development
Database GUI application
Scientific and Numeric Computing
SYST
Business Applications
Console Based Application
[Link] are the features in Python?
Answer:
Independent Platform
Object oriented
Flexible
Structure oriented
Portable
Simple
[Link] python, case sensitive language or not?
Answer:
Yes, python is a case sensitive language
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 2
[Link] indentation is required in Python?
Answer:
ECH
Indentation is necessary for Python. It specifies a block of code. All code within loops,
classes, functions, etc. And also it is specified within the indented block. It is usually done
by using four space characters. If your code is not indented necessarily, it will not execute
accurately and will throw errors as well.
[Link] is an iterator in Python?
Answer:
An iterator is an object which implements the iterator protocol.
It has a __next__() method which returns the next item in iteration, also iterators are
objects which can iterate objects like list, string, etc.
[Link] python is called an interpreted language?
Answer:
An interpreted language is any programming language which is not in machine level
code before run time. Therefore, python is an interpreted language.
SYST
[Link] is comment?
Answer:
Python comments are statements that are not executed by the compiler.
It is not considered as a part of program.
.
[Link] are the types of comments in Python?
Answer:
There are two types of comment in Python.
Single line comment
Multi line comment
[Link] is single line comment?
Answer:
It is used to comment only one line.
Hash (#) is used for single line comment.
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 3
[Link] is multiline comment?
Answer:
ECH
It is used to comment a block of code.
Triple quotes are used to multiline comment starts with ‘’’ and ends with ‘’’.
[Link] is Keyword?
Answer:
The word which is predefined in the library is called keyword.
Keywords cannot use as a variable function name, class name or any other identifier.
[Link] is Float function?
Answer:
Float () is a predefined function which is used to convert given data into float.
[Link] is int() function?
Answer:
int() is a predefined function which is used to convert string into integer.
SYST
[Link] is print in Python?
Answer:
It is a predefined function which is used to print data or information..
[Link] can you convert a number to a string?
Answer:
In order to convert a number into a string, use the inbuilt function str(). If you want a
octal or hexadecimal representation, use the inbuilt function oct() or hex().
18. What is Global variable?
Answer:
Variable are only referenced outside of that function known as global variable
[Link] is an Operator?
Answer:
It is a special symbol which is used to perform logical or mathematical operation on
data or variable
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 4
[Link] are the types of operator in Python?
ECH
Answer:
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Bit-wise operators
Membership operators
Identity operators
21. What is Operand?
Answer:
It is a data or variable on which the operation is to be performed
22. What is the use of // operator in Python?
Answer:
It is a Floor Division operator, which is used for dividing two operands with the result
as a quotient showing only digits before the decimal point. For instance, 10//5 = 2 and
10.0//5.0 = 2.0
SYST
[Link] is the purpose of relational operators in Python?
Answer:
The purpose of relational operators in Python is to compare values.
[Link] are assignment operators in Python?
Answer:
The assignment operators in Python can help in combining all the arithmetic operators
with the assignment symbol.
[Link] are membership operators?
Answer:
With the operators ‘in’ and ‘not in’
print('me' in 'disappointment')
o/p: True
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 5
[Link] to differentiate Identity operators & Membership operators?
ECH
Answer:
Unlike membership operators, the identity operators compare the values to find out if
they have the same value or not
[Link] is import method?
Answer:
Import is a keyword, to access the script from another python file or module.
[Link] is Input?
Answer:
Input () is a predefined function which is used to take user input in python.
Default user input is of type string
[Link] is “if statement”?
Answer:
If the condition is true its body will execute otherwise does not execute
[Link] is meant by for loop?
SYST
Answer:
For loop is used for sequential [Link] can be used to traverse string or array. For
loop is used to iterate over a sequence list, string, tuple, etc., Iterating over a sequence
is called traversal.
[Link] to print the star (*) pattern without newline and space?
Answer:
Code to print the star(*) pattern without newline and space:
for i in range(0, 20):
print('*', end="")
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 6
[Link] will you create the following pattern using Python?
Answer:
ECH
*
**
***
****
o/p:
for i in range(1,6):
for j in range(1,i+1):
print('*',end='')
print(‘\n’)
[Link] is list in Python?
Answer:
It is a collection of data of different data type.
It is used to store list of values.
A list is created by comma separated values between square brackets.
34. What is clear () function in list?
Answer:
SYST
This function is used to empty the list.
[Link] are the built-in -type does python provides?
Answer:
Mutable:
List
Sets
Dictionaries
Immutable:
Strings
Tuples
Numbers
[Link] can you count duplicate elements in a given list?
Answer:
Count duplicate elements in a given list
list1 = [2, 3, 4, 3, 10, 3, 5, 6, 3]
e = [Link](3)
print('The count of element: 3 is ', e)
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 7
[Link] is meant by continue statement?
ECH
Answer:
It is used to skip the next statement and continue the loop. This mostly used with loop.
[Link] is copy () function in list?
Answer:
This function copies the elements one list into another.
[Link] is count function in list?
Answer:
This method counts the number of occurrence of particular item in a list.
[Link] is docstring in Python?
Answer:
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.
[Link] is meant by extend in list?
SYST
Answer:
This function is used to join two lists
[Link] is append() function in list?
Answer:
It is used add the new element at the end of the list.
[Link] is break statement?
Answer:
It terminates the current loop. Mostly used in for and while loop.
[Link] is negative index in python?
Answer:
Python sequence can be index in positive and negative numbers.
For positive index, starts with 0 an soon. And negative index starts with (-1) in the last
index.
[Link] is meant by Pass Python?
Answer:
Pass means no operation python statement
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 8
[Link] is reverse function in list?
Answer:
ECH
This function reverses elements of the list
[Link] is pop () function in list?
Answer:
This function deletes the element of given [Link] deletes last item if we do not pass
index.
[Link] is insert () function in list?
Answer:
Insert function is used to add new items into list at particular index.
[Link] is meant by jump statement?
Answer:
It is used to transfer the control from one point to another point in the program.
[Link] is sort function in list?
Answer:
This function sorts the list in ascending order or descending order.
SYST
[Link] does len() do?
Answer:
It is used to determine the length of a string, a list, an array, etc.
Example:
S="ABCD"
print(len(S))
52. What is meant by Tuple?
Answer:
It is a collection of data of different data types.
We cannot change the value of tuples.
A tuple is created using parentheses.
[Link] the output of the following piece of code?
Answer:
tuple=(123,'mani',20,'trichy')
tuple*=2
print(tuple)
o/p: (123, 'mani', 20, 'trichy', 123, 'mani', 20, 'trichy')
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 9
54. What does the following code give us?
Answer:
ECH
b=(1)
print(type(b))
b=(1,)
print(type(b))
[Link] is difference between python Arrays and Lists?
Answer:
Arrays:
Arrays in python can only contain same data type of elements.
Homogeneous
Consumes far less memory that lists
Lists:
List in python can contain elements of different data types.
Heterogeneous
Consuming large memory
[Link] will the following code output?
SYST
Answer:
word=’abcdefghij’
word[:3]+word[3:]
The output is ‘abcdefghij’. The first slice gives us ‘abc’, the next gives us ‘defghij’.
[Link] is the difference between List and Tuple?
Answer:
The difference between list and tuple is that list is mutable while tuple is not. Tuple can
be hashed,
For example, as a key for dictionaries
[Link] about Slicing?
Answer:
A mechanism to select a range of items from sequence types like list, tuple, strings etc.,
is known as slicing.
[Link] are sets in python?
Answer:
It is an unordered collection of data of different data types.
Set does not contain duplicate elements. A set is created using curly brackets
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 10
[Link] is string in python?
Answer:
ECH
String is a collection of [Link] is created by using single quotes or double quotes.
61. How will you capitalize the first letter of string?
Answer:
In Python, capitalize () method capitalizes the first letter of a string. If the string
already consists of a capital letter at the beginning, then, it returns the original string..
62. How will you convert a string to all lowercase
Answer:
To convert a string to lowercase, lower() function can be used.
S="ABCD"
print([Link]())
[Link] if you want to toggle case for a Python string?
Answer:
print('SystECh'.swapcase())
o/p:
sYSTecH
SYST
[Link] does break, continue and pass works in python?
Answer:
Allows loop termination when some condition is met and the control is
Break
transferred to the next statement.
Allows skipping some part of a loop when some specific condition is
Continue
met and the control is transferred to the beginning of the loop
Used when you need some block of code syntactically, but you want
Pass to skip its execution. This is basically a null operation. Nothing
happens when this is executed.
[Link] is function in python?
Answer:
It is a collection of statement that performs on a specific task.
It executes when it is called by its name
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 11
[Link] is function overriding?
ECH
Answer:
Function with same name and same parameters is called function overriding.
[Link] is the split function used for?
Answer:
The split function breaks the string into shorter strings using the defined separator.
It returns the list of all the words present in the string.
[Link] is meant by Parameters and Arguments?
Answer:
Parameters are the names listed in the function definition.
Arguments are the values passed to the function while invoking.
[Link] are packing operators in Python? How to use them?
Answer:
The packing operators are used to collect multiple arguments in functions.
They are known as arbitrary arguments.
SYST
[Link] is Local variable?
Answer:
If a variable is assigned anywhere within the function’s body its assumed to be local.
[Link] are python libraries?
Answer:
Python libraries are a collection of python packages.
Some of majorly used python libraries are;
NumPy
Pandas
Matplotlib
scikit-learn,
PyTorch and many more.
[Link] are modules in python?
Answer:
A module is a collection of statement in which we store functions, classes and
variables.
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 12
[Link] are some of the most commonly used built-in modules in Python?
ECH
Answer:
Python modules are the files having python code which can be functions, variables or
classes. These go by .py extension.
The most commonly available built-in modules are:
Os
Random
Datetime
Sys
Math
[Link] is a lambda function?
Answer:
A lambda is an anonymous function. This function can have any number of
parameters but, can have just one statement.
Example: X=lambda a,b:a8b
Print(X(2,4))
SYST
[Link] Python have Oops concepts?
Answer:
Python is an object-oriented programming language .This means that any program can
be solved in python by creating an object model. However, python can be treated as
well as structural language.
[Link] is class in Python?
Answer:
It is a collection of data members and member’s functions.
Data members are the variable used inside class
Member functions are the function used inside class
It is also called user defined data type
[Link] is Parent class?
Answer:
The class which is inherited by another class is called parent or base class.
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 13
[Link] is Child class?
Answer:
ECH
The class which inherits the property of another class is called child or sub or derived
class.
[Link] is self in python?
Answer:
Self is an instance or an object of a class .it helps to differentiate between the methods
and attributes of a class with local variables.
[Link] python support multiple inheritances?
Answer:
Multiple inheritances mean that a class can be derived from more than one parent
classes. Python does support multiple inheritances.
[Link] are the class variables in python?
Answer:
Private variable
Public variable
Protected variable
SYST
[Link] is inheritance?
Answer:
The process of getting property of one class into another class is called inheritance
[Link] is __init__ in python?
Answer:
__init__ is a method or constructor in python. This method is automatically called to
allocate memory when a new object is created. All classes have the __init__ method.
[Link] is operator overloading?
Answer:
Operator overloading in python is a single operation based on the class (type) of
operands. Python operators work for built –in classes, the same operator behaves
differently with different types.
85..What is Encapsulation in python?
Answer:
Encapsulation is one of the fundamental concepts in object-oriented programming
(OOP). It describes the idea of covering data and the methods that work on data within
one unit.
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page 14
[Link] is polymorphism in python?
Answer:
ECH
Polymorphism means the ability to take multiple forms. So, for instance, if the parent
class has a method named ABC then the child class also has a method with the same
name ABC having its own parameters and variables. Python allows polymorphism.
[Link] is Data Abstraction?
Answer:
Abstraction means data hiding
If we want to perform data hiding then it can be done by using (__) prefix with variables
then they cannot be accessed outside that function
[Link] is file handling in python?
Answer:
File handling is a mechanism to store the data on the disk permanently.
There are several functions for creating reading, writing, updating and deleting files.
[Link] is file operation in python?
Answer:
1. Opening of file.
2. Writing into a file
SYST
3. Appending data into a file.
4. Reading from a file.
5. Closing of file.
[Link] is read () function in file handling?
Answer:
read () function is used read content of a file.
[Link] do you open a file for writing?
Answer:
_file=open('[Link]','w')
This opens the file in writing mode. You should close it once you’re done.
[Link]()
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page15
[Link] example of sleep() function in Python
Answer:
ECH
Example of sleep() function in Python
Import time
print("Welcome to SYSTECH GROUP")
[Link](5)
print("This message will be printed after a wait of 5 seconds")
[Link] are Reasons of Exception?
Answer:
Mismatched input:
Suppose that we are entering our name in place of age, causing exception because age
is data type int and name will be string.
Defined Data type:
Class keyword is used to create class
[Link] is try block?
Answer:
SYST
It is the place where actual code is written and exception occurs.
[Link] is except block?
Answer:
Except block is intended to catch the error and handle the exception condition. We can
have multiline except blocks to handle different types of exception and perform
different actions when the exceptions occur.
[Link] is finally block?
Answer:
This block executes either exception occurs or does not occurs.
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page16
97. Explain important Python errors?
Answer:
ECH
The important Python errors are
1) Arithmetic Error, 2) Import Error, and 3) Index Error.
Arithmetic Error:
Arithmetic Error acts as a, base class for all arithmetic exceptions. It is raised for errors
in arithmetic operations.
Import Error:
Import Error is raised when you are trying to import a module which does not present.
This kind of exception occurs if you have made a typing mistake in the module name or
the module which is not present in the standard path.
Index Error:
An Index Error is raised when you try to refer a sequence which is out of range.
[Link] is the output of the following code?
Answer:
SYST
first = [1, 2, 3, 4, 5]
second = first
[Link](6)
print(first)
print(second)
o/p:
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
[Link] a file is deleted in Python?
Answer:
The file can be deleted by either of these commands:
[Link](filename)
[Link](filename)
[Link]
sy
roup contact@
systechg 7502202555
[Link]
Page17
[Link] is difference between python and other programming languages?
Answer:
. C C++ PYTHON
Longer lines of code as 3-5 times shorter than
Longer lines of code as
compared to python. C/C++ programs.
compared to python.
Longer lines of code as Python has no
Longer lines of code as
compared to python. declaration.
compared to python.
C is a compiled C++ is a compiled Python is an
language. language. interpreted language.
Python supports
C++ supports both procedural, object-
C supports procedural procedural and object oriented, and
programming. oriented programming. functional
programming.
C++ support both single
Python supports5 types
C supports procedural and multiple
of inheritance
programming. inheritance
[Link]
sy
roup contact@
systechg 7502202555
[Link]
group
systech
Trichy Coimbatore
Aruvi Block, 1st Floor, St. Paul’s complex, Ajay building,
Bharathiyar Salai, Cantonment, 9th street, Cross Cut Road, Gandhipuram,
Trichy – 620001 Coimbatore – 641012
+91 431 241 0960 +91 422 2493658
75022 02555 9080432873
contact@[Link] contact@[Link]
[Link] [Link]
Chennai Coming Soon...!