Python Interview Questions with Answers

Pavithra M
2 min readJul 1, 2021

--

1. How to convert a number into a string?

One of the most common python interview questions. We can use the inbuilt str() function. For an octal or hexadecimal representation, we can use the other inbuilt functions like oct() or hex().

2. What is the use of the // operator in Python?

Using the // operator between 2 numbers gives the quotient when the numerator is divided from the denominator. It is called the Floor Division operator. It is one of the general questions from the Python interview questions and answers guide.

3.Does Python have a main() function?

Yes, it does. It is executed automatically whenever we run a Python script. To override this natural flow of things, we can also use the if statement.

4.What is GIL?

GIL or the Global Interpreter Lock is a mutex, used to limit access to Python objects. It synchronizes threads and prevents them from running at the same time.

5.Explain “self” in Python.

In Python, “self” is a keyword used to define an instance or object of a class. Unlike in Java, where the self is optimal, in Python, it is primarily used as the first parameter. Self helps to distinguish between the methods and attributes of a class from its local variables.

The self variable in the __init__ method refers to the newly created object or instance, while in other methods, it pertains to the object or instance whose method was called.

6.What is PEP 8?

PEP or Python Enhancement Proposal is a set of rules that specify how to format Python code for maximum readability. It is an official design document that provides relevant information to the Python Community, such as describing a new Python feature or a Python process. PEP 8 is an important document that includes the style guidelines for Python Code. Anyone who wishes to contribute to the Python open-source community must strictly abide by these style guidelines.

7.What is __init__?

In Python,__init__ is a method or constructor. It is automatically called to allocate memory when a new object or instance of a class is created. All classes have the __init__ method.

8.What is the lambda function?

An anonymous function is known as a lambda function. This function can have only one statement but can have any number of parameters.

a = lambda x,y : x+y

print(a(5, 6))

9. What is namespace in Python?

A naming system used to make sure that names are unique to avoid naming conflicts refers to as Namespace.

10.Is indentation necessary in Python?

Answer: Indentation is required in Python if not done properly the code is not executed properly and might throw errors. Indentation is usually done using four space characters.

Also Read, Top MNC Python Interview Questions with Answers

Accenture

Standard Chartered

Rectras

Blackboard

Infosys

Hexaware

PayPal

Wipro

--

--