/    /  Python – Interview Questions Part 3

1. Explain pickling and unpickling?

Answer: Pickling accepts any python object and converts in to string representation and dumps it into a file by using dump function while unpickling retrieves the original python object from the stored string representation, where it is an  is the inverse of pickling.

 

2. What is PEP 8?

Answer: Pep 8 is a set of recommendation, about how to write your Python code more readable. It is called coding convention. We use this   bring consistency in our code; with consistency it is easier for other developers to read the code.

 

3. What are Python decorators?

Answer: A specific change that we make in Python syntax to alter functions easily is called Python decorators. They help to make our code shorter and clean to look at. Without these code will look messy and difficult to maintain.

 

4. What is Dictionary or List comprehensions are?

Answer: Dictionary or List is the syntax constructions to ease the creation, based on the existing iterable. They operate the same way but use two variables, the key, and its value, instead of using typically single value for list iteration.

 

5. What are the built-in types in python?

Answer: They are of two types mutable and immutable

In mutable built in types are:

1. List

2. Sets

3. Dictionaries

In immutable built in types are:

1. Strings

2. Tuples

3. Numbers

 

6. What are supported data types in python?

Answer: Python has five supported data types −

Numbers

String

List

Tuple

Dictionary

 

7. How will you remove last object from a list?

Answer: To remove and return last object or object from list use this command;

list.list.pop(obj=list[-1])

 

8. How will you reverse a list?

Answer: To reverse a list use this command list.reverse()

>>> l = list(range(10))

>>> l

[4, 5, 6, 7, 8]

>>> l.reverse()

>>> l

[8, 7, 6, 5, 4]

 

9. How to get indices of N maximum values in a NumPy array?

Answer: We can get the indices of N maximum values in a NumPy array using the below code:

import numpy as np

arr = np.array([1, 3, 2, 4, 5])

print(arr.argsort()[-3:][::-1])

 

10. How many kinds of sequences are supported by Python? What are they?

Answer: Python supports 7 sequence types. They are

strings,

list,

Tuple,

Unicode,

Byte array,

Xrange, and

Where xrange is deprecated in python 3.5.X.