Python Interview Questions
Python Interview Questions
Python Interview Questions
What is pep 8?
PEP stands for Python Enhancement Proposal. It is a set of rules that specify how to format Python code for
maximum readability.
What is PYTHONPATH?
It is an environment variable which 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.
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.
os
sys
math
random
data time
JSON
PYTHON INTERVIEW QUESTIONS
What are local variables and global variables in Python?
Global Variables:
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.
a=2
def add():
b=3
c=a+b
print(c)
add()
PYTHON INTERVIEW QUESTIONS
Is python case sensitive?
Yes. Python is a case sensitive language.
[4,2,5,1,3,6]
The negative index is used to remove any new-line spaces from the string and allow the string to except the last
character that is given as S[:-1].
Deep copy is used to store the values that are already copied. Deep copy doesn’t copy the reference pointers to
the objects. It makes the reference to an object and the new object that is pointed by some other object gets
stored.
Output:
1234
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 7]
[3, 4, 5]
[2, 4, 6]
PYTHON INTERVIEW QUESTIONS
Python List Operations
Consider a Lists l1 = [1, 2, 3, 4], and l2 = [5, 6, 7, 8] to perform operation.
Repetition L1*2 = [1, 2, 3, 4, 1, 2, 3, 4]
Concatenation l1+l2 = [1, 2, 3, 4, 5, 6, 7, 8]
Membership print(2 in l1) prints True.
Iteration for i in l1:
print(i)
Output
1
2
3
4
Length len(l1) = 4