Python Interview Questions
Python Interview Questions
INTERVIEW QUESTIONS
1000+ DOWNLOADS
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 1
1.What is Python?
Answer:
ECH
It is powerful, general purpose, high level, object oriented programming language.
It’s developed by Guido Van Rossum in 1991..
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 2
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.
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 3
ECH
It is used to comment a block of code.
Triple quotes are used to multiline comment starts with ‘’’ and ends with ‘’’.
13.What 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.
19.What is an Operator?
Answer:
It is a special symbol which is used to perform logical or mathematical operation on
data or variable
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 4
ECH
Answer:
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Bit-wise operators
Membership operators
Identity operators
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 5
ECH
Answer:
Unlike membership operators, the identity operators compare the values to find out if
they have the same value or not
28.What is Input?
Answer:
Input () is a predefined function which is used to take user input in python.
Default user input is of type string
31.How 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="")
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 6
ECH
*
**
***
****
o/p:
for i in range(1,6):
for j in range(1,i+1):
print('*',end='')
print(‘\n’)
Answer:
Mutable:
List
Sets
Dictionaries
Immutable:
Strings
Tuples
Numbers
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 7
ECH
Answer:
It is used to skip the next statement and continue the loop. This mostly used with loop.
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 8
ECH
This function reverses elements of the list
Example:
S="ABCD"
print(len(S))
ECH
b=(1)
print(type(b))
b=(1,)
print(type(b))
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
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 10
ECH
String is a collection of characters.it is created by using single quotes or double quotes.
o/p:
sYSTecH
SYST
64.How 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.
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.
ECH
Answer:
Function with same name and same parameters is called function overriding.
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 12
73.What 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
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page 13
ECH
The class which inherits the property of another class is called child or sub or derived
class.
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.
This opens the file in writing mode. You should close it once you’re done.
file.close()
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page15
ECH
Example of sleep() function in Python
Import time
print("Welcome to SYSTECH GROUP")
time.sleep(5)
print("This message will be printed after a wait of 5 seconds")
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:
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page16
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.
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
Page17
Answer:
. C C++ PYTHON
Python supports
C++ supports both procedural, object-
C supports procedural procedural and object oriented, and
programming. oriented programming. functional
programming.
stechgroup.in
sy
roup contact@
systechg 7502202555
www.systechgroup.in
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
[email protected] [email protected]
https://systechgroup.in/ https://systechgroup.in/