In the current scenario, Pythons are very well known and highly sorted language. Due to the versatile nature of python, there are different Jobs available for Python developer. As Python is used for multi-purpose such as web-development, Data analysis, Artificial Intelligence etc. after having the knowledge of python and with some advance level Python you can apply for these jobs. But when you go for the Interview you may have to face some questions related to the python and if you give all answer correctly it can increase your chance to get that job.
Python Interview Question for Intermediate Level
Here in this article we have provided you 20 Most frequent questions often asked in python interview.
Question: What split() function do.
Answer: split() function is basically used for split the string into a list
Question: What are Django, Pyramid, and flask in Python?
Answer: Django: Django is a full stack Python web-framework.
Pyramid: Pyramid is also a Python web-framework which is used to build large web applications.
Flask: flask is a python microframework which is basically used to build small web applications.
Question: What is map() function does in Python?
Answer: the map function accepts 2 arguments the first argument can be a function or statement and the 2nd argument is the type which iterates through the first argument.
Question: what is “None” often used to Represent?
Answer: Absence of value.
Question: What will be the output of this code?
if foo==None: print(1) else: print(2)
Question: What is floor division?
Answer: the symbol of the floor division is “//” double division sign it basically divide one value with another and give the answer an integer value.
p= 12//5 print(p)
Question: Does python have a compiler?
Answer: Yes, python does a have the compiler. It’s works automatically.
Question: Name all data type used in Python.
Answer: 1. Integer
Question: Write the statement to reverse the list.
Question: What are all the file processing mode in python?
Answer: 1. “r”= Used for reading the file
- “w”= used for write and overwrite on in the file or create the new file.
- “rw”= use for both read and write simultaneously
- “a”= it used for append the file and can create a new file too.
Question: Explain the concept of *args and ** kwargs.
Answer: *args , It is a special kind of function definition which is used to pass multiple variables as arguments to the function. *args basically used when you are not sure about how many arguments passeds to the function.
# *args syntax: def fun(*agrs): #here args is a variable you can choose other variable name too instead of args. for i in args: print(i) fun(“hellow”,”world”,”its” ,“an”, “args”,”function”) # output hellow world its an args function
**kwargs: It is special kind of function in python which allow the user to mass multiple argument in the function. But in **kwargs the argument passes in the function as dictionaries.
# e.g of **kwargs:
def fun(**kwargs): For k,v in kwargs.items(): Print(str(k) + “value is “+ str(v) fun(k1=”value 1”,k2=”value 2”,k3=”value 3”)
k1 value is value 1
k2 value is value 2
k3 value is value 3
Question: How the Python interpreter work?
Answer: The Python interpreter consists two things one is compiler and second is a virtual machine. First, the compiler takes your source code and convert it into Byte code. Byte code is simply a lower level code which is platform independent. Then the byte code is fed into the PVM(Python Virtual Machine). The PVM execute the Byte code and give the output.
Question: Explain the .py and .pyc file extension.
Answer: the .py is the file extension of the Python programme, and .pyc is the file extension of the compiled byte code file which is generated by python.
Question: What is an Exception in python?
Answer: Exception can be defined as an event that occur due to incorrect code or input.
Question: What we use to deal with the exception?
Answer: to avoid the exception we can use try/except statement. If any exception occur, the code in try block stop execution and the code in the except block start to run.
try: i=2 j=0 print(i/j) except ZeroDivisionError: print(“error has occurred because of zero division”)
an error has occurred because of zero division
Question: What is raise an exception?
Answer: to raise the exception and terminate the programme we can use raise exception statement.
print(45) raise ValueError print(34) #output
Question: Write all errors occurred in python.
Answer: Import error: it occurs when import statement fails
IndexError: when indexing of any list fails
NameError: undefined or unknown variable
SyntaxError: when the code is not written properly
TypeError: when an unappropriated variable is call.
There are many other exception or error in python. There are several exceptions in the third party libraries.
Question: What is NumPy?
Answer: it is a fundamental package which is basically used for scientific computation with Python.
Question: Give some main features of NumPy.
Answer: 1. It has a powerful N-dimensional array
- shophisticatd functions
- tools for integrating c/c++ and Fortran code
- useful linear algebra, Fourier transform, and random number capabilities.
Question: What is list comprehensions?
Answer: List comprehension is a method which can make the list in a concise way.
Lis=[i*I for i in range(10) if i%2==0]
Question: What is the difference between xrange() and range()?
Answer: both range() and xrange() shear the same properties, but the main difference occur in their return type. xrange() return the xrange object but the range return the list object.