Python Questions
Warm up for Python interview with most asked questions and answers for junior, mid, and senior roles.
What are global, protected, and private attributes in Python?
Show AnswerHide 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.
What is Pandas?
Show AnswerHide Answer
Pandas is a Python library for data manipulation and analysis. It provides high-performance, easy-to-use data structures and data analysis tools.
How to overload constructors or methods in Python?
Show AnswerHide Answer
Overloading constructors or methods in Python is done by using the __init__() method.
What is __init__?
Show AnswerHide Answer
__init__ is a special method that is called when an object is instantiated. It is used to initialize the object.
What is the usage of enumerate () function in Python?
Show AnswerHide 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.
What is a dictionary in Python?
Show AnswerHide Answer
Dictionaries are used to store data in key-value pairs.
What is the difference between deep and shallow copy?
Show AnswerHide Answer
Deep copy is a copy of the object itself while shallow copy is a copy of the object’s reference.
What is the purpose of the single underscore “_” variable in Python?
Show AnswerHide Answer
The single underscore “_” variable is used to indicate that a variable is private and should not be used outside of the class.
Explain docstring in Python?
Show AnswerHide Answer
A docstring is a string literal used to document the purpose of a Python module, function, class, or method.
What is pickling and unpickling in Python?
Show AnswerHide 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.
What are python modules?
Show AnswerHide Answer
In Python, Modules are simply files with the “. py” extension containing Python code that can be imported inside another Python Program.
What is Flask?
Show AnswerHide Answer
Flask is a web framework, it’s a Python module that lets you develop web applications easily.
What is namespace in Python?
Show AnswerHide Answer
Namespaces in Python. A namespace is a collection of currently defined symbolic names along with information about the object that each name references.
What's the difference between the list methods append() and extend()?
Show AnswerHide 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.
What is the python “with” statement designed for?
Show AnswerHide 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.
What is a "callable"?
Show AnswerHide Answer
A callable is an object that can be called. For example, a function is callable, but classes are not callable.
What is lambda functions in Python?
Show AnswerHide Answer
Lambda functions are anonymous functions in Python. They are used to create small anonymous functions.
What are decorators in Python?
Show AnswerHide Answer
Decorators are functions that are used to modify the behavior of other functions.
What is PEP 8?
Show AnswerHide Answer
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code.
What is Python literals?
Show AnswerHide Answer
Literals in Python is defined as the raw data assigned to variables or constants while programming.
What is zip() function in Python?
Show AnswerHide Answer
The zip() function in Python is used to create a sequence of tuples, and it takes any number of iterables as arguments.
What are descriptors?
Show AnswerHide Answer
Descriptors are objects that provide access to the properties of an object.
What is pickling and unpickling?
Show AnswerHide 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.
What is negative index in Python?
Show AnswerHide 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.
What is Pass in Python?
Show AnswerHide 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.