3 Weeks Beginners Guide to Ace Data Science Interview: #Day 4

Basic Interview questions related to python and it’s libraries

Vinay Vikram
Accredian
8 min readJan 31, 2020

--

About the Series

Data Science field is an exciting career choice and seeing a lot of hiring across fresh, lateral and experienced job positions. It’s one thing to know the concepts and totally another to crack the rigorous interviews for data science positions. If a candidate is aware of the different questions and the interview process, he is on the right path to an excellent career in the evolving Data Science field.

This 3-week beginners guide to Ace Data Science Interview will be a useful asset for individuals who are preparing for the Data Science interviews. Every day for the next 21 days, we will talk about the different areas of the Data Science field and cover them elaborately. So sit back and start reading the article to get a finer understanding of the Data Science field and go prepared for the interviews.

In this Data Science Interview Questions blog, I will introduce you to the most frequently asked questions on Data Science, Analytics and Machine Learning interviews. This blog is the perfect guide for you to learn all the concepts required to clear a Data Science interview. To get in-depth knowledge on Data Science, you can enroll for live Data Science Certification Training by INSAID with 24/7 support and lifetime access to all resources.

Top Python Interview Questions and Answers

Go through these top Python interview questions and land your dream job in Data Science, Machine Learning, or in the field of Python coding. Here, we have compiled the questions on topics, such as

  • Lists vs tuples
  • Inheritance example
  • Multithreading
  • important Python modules
  • Differences between NumPy and SciPy, Tkinter GUI
  • Python as an OOP and functional programming language

Question 1: Which data types are supported in Python?

Python has five standard data types:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionaries
  • Code

Question 2: What are the negative indexes and why are they used?

When we use the index to access elements from the end of a list, it’s called reverse indexing. In reverse indexing, the indexing of elements starts from the last element with the index number ‘−1’. The second last element has index ‘−2’, and so on. These indexes used in reverse indexing are called negative indexes.

Question: 3 What are split(), sub(), and subn() methods in Python?

These methods belong to Python RegEx ‘re’ module and are used to modify strings.

  • split(): This method is used to split a given string into a list.
  • sub(): This method is used to find a substring where a regex pattern matches, and then it replaces the matched substring with a different string.
  • subn(): This method is similar to the sub() method, but it returns the new string, along with the number of replacements.

Question 4: How is memory managed in Python?

  • Memory in Python is managed by Python private heap space. All Python objects and data structures are located in a private heap. This private heap is taken care of by Python Interpreter itself, and a programmer doesn’t have access to this private heap.
  • Python memory manager takes care of the allocation of Python private heap space.
  • Memory for Python private heap space is made available by Python’s in-built garbage collector, which recycles and frees up all the unused memory.

Question 5: What is the difference between lists and tuples?

Question 6: Write an efficient code to count the number of capital letters in a given string? string="Not mAnY Capital Letters".

import re
string = "Not mAnY Capital Letters"
len(re.findall(r'[A-Z]',string))

Question 7: Write a code to sort a numerical list in Python.

The following code can be used to sort a numerical list in Python:

list = [2, 5, 7, 8, 1]list = [int(i) for i in list]list.sort()print (list)

Question 8: How will you reverse a list in Python?

In python, For reversal of the list, we can simply use the .reverse() function.

list = [2, 5, 7, 8, 1]
list.reverse()
list

Question 9: How are range and xrange different from one another?

Functions in Python, range() and xrange() are used to iterate in a for loop for a fixed number of times. Functionality-wise, both these functions are the same. The difference comes when talking about Python version i.e Python 3 vs Python 2.

Question 10: What is a map function in Python?

The map() function in Python has two parameters, function and iterable. The map() function takes a function as an argument and then applies that function to all the elements of an iterable, passed to it as another argument. It returns an object list of results.

Syntax: map(function, iterable)

def calculate_cube(n):
return n*n*n
numbers = (2, 3, 4, 5)
result = map(calculate_cube, numbers)
print(result)

Question 11: Explain all file processing modes supported in Python.

Python has various file processing modes.

For opening files, there are three modes:

  • read-only mode (r)
  • write-only mode (w)
  • read-write mode (rw)

For opening a text file using the above modes, we will have to append ‘t’ with them as follows:

  • read-only mode (rt)
  • write-only mode (wt)
  • read-write mode (rwt)

Similarly, a binary file can be opened by appending ‘b’.

Question 12: How are Python arrays and Python lists different from each other?

In Python, when we say ‘arrays’, we are usually referring to ‘lists’. It is because lists are fundamental to Python just as arrays are fundamental to most of the low-level languages.

Question 13: Differentiate between NumPy and SciPy Python Library.

Question 14: Which of the following is an invalid statement?

(a) xyz = 1,000,000

(b) x y z = 1000 2000 3000

(c) x,y,z = 1000, 2000, 3000

(d) x_y_z = 1,000,000

Answer: b

Question 15: What would be the output if I run the following code block?

list1 = [20, 33, 202, 54, 65]
print(list1[-2])

Answer: 54

Question 16: What is __init__ in Python?

In OOP terminology, __init__ is a reserved method in Python classes. The __init__ method is called automatically whenever a new object is initiated. This method allocates memory to the new object as soon as it is created. This method can also be used to initialize variables.

Question 17: What is a self-keyword in Python?

Self-keyword is used as the first parameter of a function inside a class that represents the instance of the class. The object or the instance of the class is automatically passed to the method that it belongs to and is received in the self-keyword.

Question 18: What is the difference between append() and extend() methods?

Both append() and extend() methods are methods used to add elements at the end of a list.

  • append(element): Adds the given element at the end of the list that called this append() method
  • extend(another-list): Adds the elements of another list at the end of the list that called this extend() method

Question 17: What do you understand by Tkinter?

Tkinter is an in-built Python module that is used to create GUI applications. It is Python’s standard toolkit for GUI development. Tkinter comes with Python, so there is no installation needed

Question 18: What is the use of the “lambda” function in Python?

A lambda function is a small anonymous function.

A lambda function can take any number of arguments, but can only have one expression.

Syntax: lambda arguments: expression

x = lambda a, b, c : a + b + c
print(x(5, 6, 2))

Question 19: Do we need to declare variables with data types in Python?

No, Python is a dynamically typed language, I.E., Python Interpreter automatically identifies the data type of a variable based on the type of value assigned to the variable.

Question 20: What do you mean by *args and **kwargs?

  • When we want to pass a list or a tuple of values, we use *args.
def func(*args):
for i in args:
print(i)
func(3,2,1,4,7)
  • **kwargs takes keyword arguments when we don’t know how many there will be.
def func(**kwargs):
for i in kwargs:
print(i,kwargs[i])
func(a=1,b=3,c=5)

Question 21: What Is Inheritance In Python Programming?

Inheritance is an OOP mechanism that allows an object to access its parent class features. It carries forward the base class functionality to the child.

We do it intentionally to abstract away the similar code in different classes.

The common code rests with the base class, and the child class objects can access it via inheritance. Check out the given below example.

class PC: # Base class
processor = "Intel" # Common attribute
def set_processor(self, new_processor):
processor = new_processor

class Desktop(PC): # Derived class
os = "Windows OS" # Personalized attribute
ram = "32 GB"

class Laptop(PC): # Derived class
os = "Windows 10 Pro 64" # Personalized attribute
ram = "16 GB"

desk = Desktop()
print(desk.processor, desk.os, desk.ram)

lap = Laptop()
print(lap.processor, lap.os, lap.ram)

Any more queries? Feel free to share all your doubts with us.

If this blog helped you in any way, then do Follow and Clap👏, because your encouragement catalyzes inspiration and helps to create more cool stuff like this.

Check what’s on Day1, and Day2.

Final Thoughts and Closing Comments

There are some vital points many people fail to understand while they pursue their Data Science or AI journey. If you are one of them and looking for a way to counterbalance these cons, check out the certification programs provided by INSAID on their website. If you liked this story, I recommend you to go with the Global Certificate in Data Science & AI because this one will cover your foundations, machine learning algorithms, and deep neural networks (basic to advance).

--

--

Vinay Vikram
Accredian

Artificial Intelligence Researcher at @MOTHERSON | Check My Data Science Portfolio: https://vikramvinay.github.io/