Python Interview Questions (Part 2)

What is pickling and unpickling?

Pickling in Python refers to the process of converting a Python object into a byte stream, while unpickling is the process of reconstructing the original object from the byte stream. This is often used to save and restore complex data structures.

Is indentation required in Python?

Yes, indentation is a fundamental aspect of Python's syntax. Proper indentation is crucial for indicating code blocks, such as loops and functions. Indentation enhances code readability and enforces a clean structure.

Does Python have OOP concepts?

Yes, Python is an object-oriented programming (OOP) language. It supports encapsulation, inheritance, and polymorphism, allowing developers to structure and organize their code using classes and objects.

What is monkey patching in Python?

Monkey patching refers to the practice of dynamically modifying or extending modules, classes, or functions at runtime. It can be useful for adding features or fixing bugs in third-party code without altering the original source.

Does Python make use of access specifiers?

Python does not have traditional access specifiers like public, private, or protected as in some other languages. Instead, it uses naming conventions like a single underscore prefix for indicating a "protected" attribute and a double underscore prefix for "private" attributes.

What are negative indices?

In Python, negative indices are used to access elements from the end of a sequence. -1 represents the last element, -2 the second-to-last, and so on.

What is the purpose of the ** operator?

The ** operator in Python is used for exponentiation. It raises a number to the power of another number. For example, 2 ** 3 yields 8.

What is the purpose of the // operator?

The // operator in Python performs floor division, which yields the quotient of a division rounded down to the nearest integer. It discards the remainder.

What are membership operators?

Membership operators (in and not in) are used to test if a value exists in a sequence, such as a list, tuple, or string.

What is the zip() function in Python?

The zip() function combines multiple sequences into a single iterable, creating pairs of corresponding elements from the input sequences. It's often used for parallel iteration.

Difference between Deep copy and Shallow copy?

A deep copy creates a new copy of an object and recursively copies all the objects it references, while a shallow copy creates a new object and copies references to objects within the original, without recursively copying those referenced objects.

How to determine the type of an object?

You can determine the type of an object using the type() function, which returns the class type of an object. Alternatively, you can use the isinstance() function to check if an object is an instance of a specific class or its subclasses.