Python Coding Interview Questions

Avatto > > DATA SCIENTIST > > SHORT QUESTIONS > > Python Coding Interview Questions

In a normal dictionary in Python, there is no order maintained between keys. To solve this problem, we can use OrderDict class in Python. This class is available for use since version 2.7.
It is similar to a dictionary in Python, but it maintains the insertion order of keys in the dictionary collection.
A Module is a script written in Python with import statements, classes, functions, etc. We can use a module in another Python script by importing it or by giving the complete namespace.
With Modules, we can divide the functionality of our application in smaller chunks that can be easily managed.
Python provides // operator to perform floor division of a number by another. The result of // operator is a whole number (without decimal part) quotient that we get by dividing the left number with the right number.
It can also be used floordiv(a,b).
E.g.
10// 4 = 2
-10//4 = -3
In Python, we have a built-in function zip() that can be used to aggregate all the Iterable objects of an Iterator.
We can use it to aggregate Iterable objects from two iterators as well.
E.g.

list_1 = ['a', 'b', 'c']
list_2 = ['1', '2', '3'] for a, b in zip(list_1, list_2):
print a, b

Output:
a1
b2
c3
By using zip() function we can divide our input data from different sources into fixed number of sets.
None is a reserved keyword used in Python for null objects. It is neither a null value nor a null pointer. It is an actual object in Python. But there is only one instance of None in a Python environment.
We can use None as a default argument in a function.

During comparison we have to use “is” operator instead of “==” for None.