Python Questions

Warm up for Python interview with most asked questions and answers for junior, mid, and senior roles.

Mid

What are global, protected, and private attributes in Python?

Show Answer

Variables with the public access modifiers can be accessed anywhere inside or outside the class

 

The private variables can only be accessed inside the class,

 

Protected variables can be accessed within the same package.

Mid

What is Pandas?

Show Answer

Pandas is a Python library for data manipulation and analysis. It provides high-performance, easy-to-use data structures and data analysis tools.

Mid

How to overload constructors or methods in Python?

Show Answer

Overloading constructors or methods in Python is done by using the __init__() method.

Mid

What is __init__?

Show Answer

__init__ is a special method that is called when an object is instantiated. It is used to initialize the object.

Mid

What is the usage of enumerate () function in Python?

Show Answer

The enumerate function returns an enumerate object. It is a way to iterate over an iterable and return both the index and value of each item in the iterable.

Mid

What is a dictionary in Python?

Show Answer

Dictionaries are used to store data in key-value pairs.

Mid

What is the difference between deep and shallow copy?

Show Answer

Deep copy is a copy of the object itself while shallow copy is a copy of the object’s reference.

Mid

What is the purpose of the single underscore “_” variable in Python?

Show Answer

The single underscore “_” variable is used to indicate that a variable is private and should not be used outside of the class.

Mid

Explain docstring in Python?

Show Answer

A docstring is a string literal used to document the purpose of a Python module, function, class, or method.

Mid

What is pickling and unpickling in Python?

Show Answer

Python docstrings are the string literals that appear right after the definition of a function, method, class, or module. Let's take an example.

Mid

What are python modules?

Show Answer

In Python, Modules are simply files with the “. py” extension containing Python code that can be imported inside another Python Program.

Mid

What is Flask?

Show Answer

Flask is a web framework, it’s a Python module that lets you develop web applications easily.

Mid

What is namespace in Python?

Show Answer

Namespaces in Python. A namespace is a collection of currently defined symbolic names along with information about the object that each name references.

Mid

What's the difference between the list methods append() and extend()?

Show Answer

The append() adds a single element to the end of the list while . extend() can add multiple individual elements to the end of the list.

Mid

What is the python “with” statement designed for?

Show Answer

The with statement in Python is used for resource management and exception handling. You'd most likely find it when working with file streams. 

Mid

What is a "callable"?

Show Answer

A callable is an object that can be called. For example, a function is callable, but classes are not callable. 

Mid

What is lambda functions in Python?

Show Answer

Lambda functions are anonymous functions in Python. They are used to create small anonymous functions.

Mid

What are decorators in Python?

Show Answer

Decorators are functions that are used to modify the behavior of other functions.

Mid

What is PEP 8?

Show Answer

PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code.

Mid

What is Python literals?

Show Answer

Literals in Python is defined as the raw data assigned to variables or constants while programming.

Mid

What is zip() function in Python?

Show Answer

The zip() function in Python is used to create a sequence of tuples, and it takes any number of iterables as arguments.

Mid

What are descriptors?

Show Answer

Descriptors are objects that provide access to the properties of an object.

Mid

What is pickling and unpickling?

Show Answer

Pickling is the process of converting a Python object into a byte stream, and unpickling is the process of converting a byte stream into a Python object.

Mid

What is negative index in Python?

Show Answer

Negative index in Python is used to access the elements of a list or a tuple from the end of the list or tuple.

Mid

What is Pass in Python?

Show Answer

The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed.