Ebook Python Interview Guide
Ebook Python Interview Guide
PYTHON
Interview Guide
1 | www.simplilearn.com
Ace Your Python
Interview
Today, the world of Big Data and Are you applying for a job that
Analytics has gained enormous involves knowledge of Python? If yes,
popularity and consequently, we have your back. We have clubbed a
Python has become the preferred list of 50 most popular questions you
programming language among tech can expect in an interview. So prepare
professionals. Scalability, simpler ahead of time, and crack your python-
coding, and its collection of libraries related interview in the first go.
and frameworks are just some of the
features that make Python suitable
for companies engaged in data or
machine learning-based initiatives.
2 | www.simplilearn.com
Interview Guide
Topics
Covered
• Python Operators
• Python Arrays
• Output questions
• Django
• Matplotlib
• Scikit Learn
3 | www.simplilearn.com
Interview Guide
A: Deepcopy creates a different object and populates it with the child objects of
the original object. Therefore, changes in the original object are not reflected in
the copy.
Shallow copy creates a different object and populates it with the references of
the child objects within the original object. Therefore, changes in the original
object are reflected in the copy.
A: Django is a web service used to build your web pages. Its architecture is as
shown:
Template: the front end of the web page
Model: the back end where the data is stored
View: It interacts with the model and template and maps it to the URL
Django: serves the page to the user
Q: What Advantage Does the Numpy Array Have over a Nested List?
A: Numpy is written in C so that all its complexities are backed into a simple to use
a module. Lists, on the other hand, are dynamically typed. Therefore, Python
must check the data type of each element every time it uses it. This makes
Numpy arrays much faster than lists.
Numpy has a lot of additional functionality that list doesn’t offer; for instance, a
lot of things can be automated in Numpy.
4 | www.simplilearn.com
Interview Guide
Pickling Unpickling
Converting a Python object Converting a byte stream to
hierarchy to a byte stream is a Python object hierarchy is
called pickling called unpickling
If you just created a neural network model, you can save that model to your
hard drive, pickle it, and then unpickle to bring it back into another software
program or to use it at a later time.
A: Arguments are passed in python by a reference. This means that any changes
made within a function are reflected in the original object.
Consider two sets of code shown below:
In the first example, we only assigned a value to one element of ‘l’, so the
output is [3, 2, 3, 4].
In the second example, we have created a whole new object for ‘l’. But, the
values [3, 2, 3, 4] doesn’t show up in the output as it is outside the definition of
the function.
5 | www.simplilearn.com
Interview Guide
6 | www.simplilearn.com
Interview Guide
7 | www.simplilearn.com
Interview Guide
8 | www.simplilearn.com
Interview Guide
9 | www.simplilearn.com
Interview Guide
splits >>fun(1)
Example - >>fun(1,25,6)
>>var=“Red,Blue,Green,Orange” In the above code, * indicates that
there are multiple arguments of a
>>lst=var.split(“,”,2)
variable.
>>print(lst)
Output:
Q: What Are *args and *kwargs?
[‘Red’,’Blue’,’Green, Orange’]
Here, we have a variable var whose A: *args
values are to be split with commas. • I t is used in a function prototype
Note that ‘2’ indicates that only the to accept a varying number of
first two values will be split. arguments.
• It's an iterable object.
Q: Is Python Object-oriented or • Usage - def fun(*args)
Functional Programming?
10 | www.simplilearn.com
Interview Guide
4. None of these
Q: How Do You Get Indices of N
Maximum Values in a Numpy A: 3. from sklearn.tree import
Array? DecisionTreeClassifier
A: >>import numpy as np
>>arr=np.array([1, 3, 2, 4, 5]) Q: You Have Uploaded the Dataset
in Csv Format on Google
>>print(arr.argsort( ) [ -N: ][: : -1])
Spreadsheet and Shared It
Publicly. How Can You Access
Q: How Would You Obtain the This in Python?
Res_set from the Train_set and
A: We can use the following code:
the Test_set from Below?
>>link = https://docs.google.com/
A: >>train_set=np.array([1, 2, 3]) spreadsheets/d/...
>>test_set=np.array([[0, 1, 2], [1, 2, >>source = StringIO.
11 | www.simplilearn.com
Interview Guide
StringIO(requests.get(link). 1. pd.read_csv(“temp.csv”,
content)) compression=’gzip’)
>>data = pd.read_csv(source)
2. pd.read_csv(“temp.csv”,
dialect=’str’)
Q: What Is the Difference Between
the Two Data Series given 3. pd.read_csv(“temp.csv”,
Below? encoding=’utf-8)
12 | www.simplilearn.com
Interview Guide
Q. How Would You Reset the Index Numpy by the (N-1)Th Column.
of a Dataframe to a given List? A: This can be achieved by using
Choose the Correct Option. argsort() function. Let us take an
1. df.reset_index(new_index,) array X; the code to sort the (n-1)th
column will be x[x [: n-2].argsoft()]
2. df.reindex(new_index,)
The code is as shown below:
3. df.reindex_like(new_index,)
>>import numpy as np
4. None of these
>>X=np.
A: 3. df.reindex_like(new_index,) array([[1,2,3],[0,5,2],[2,3,4]])
>>X[X[:,1].argsort()]
Q. How Can You Copy Objects in Output:
Python? array([[1,2,3],[0,5,2],[2,3,4]])
A: The function used to copy objects
in Python are:
Q. How Do You Create a Series
copy.copy for shallow copy and
from a List, Numpy Array, and
copy.deepcopy() for deep copy Dictionary?
Looking forward to a career as A: The code is as shown:
a Data Scientist? Check out the
>> #Input
Data Science with Python Training
Course and get certified today. >>import numpy as np
>>import pandas as pd
Q. What Is the Difference Between >>mylist =
range() and xrange() Functions list('abcedfghijklmnopqrstuvwxyz’)
in Python? >>myarr = np.arange(26)
A: range() >>mydict = dict(zip(mylist, myarr))
range returns a Python list object >> #Solution
xrange() >>ser1 = pd.Series(mylist)
xrange returns an xrange object >>ser2 = pd.Series(myarr)
>>ser3 = pd.Series(mydict)
Q. How Can You Check Whether a >>print(ser3.head())
Pandas Dataframe Is Empty or
Not?
Q. How Do You Get the Items Not
A: The attribute df.empty is used Common to Both Series a and
to check whether a pandas data Series B?
frame is empty or not.
A: >> #Input
>>import pandas as pd
>>import pandas as pd
>>df=pd.DataFrame({A:[]})
>>ser1 = pd.Series([1, 2, 3, 4, 5])
>>df.empty
>>ser2 = pd.Series([4, 5, 6, 7, 8])
Output: True
>> #Solution
>>ser_u = pd.Series(np.
Q. Write a Code to Sort an Array in union1d(ser1, ser2)) # union
13 | www.simplilearn.com
Interview Guide
14 | www.simplilearn.com
Interview Guide
INDIA USA
Simplilearn Solutions Pvt Ltd. Simplilearn Americas, Inc.
# 53/1 C, Manoj Arcade, 24th Main, 201 Spear Street, Suite 1100,
Harlkunte San Francisco, CA 94105
2nd Sector, HSR Layout United States
Bangalore: 560102 Phone No: +1-844-532-7688
Call us at: 1800-212-7688
www.simplilearn.com
15 | www.simplilearn.com