Your cart is empty

Continue shopping

Your cart

Python Interview Questions

Python Interview Questions - Email Gate

Top 20 Python Interview Questions

1. What is Python? What are its key features?

Python is a high-level, interpreted programming language known for its simplicity and readability. Key features include: - Dynamic typing - Object-oriented programming support - Extensive standard library - Platform independence - Rich ecosystem of third-party packages

2. What is the difference between lists and tuples in Python?

Lists are mutable (can be modified after creation) while tuples are immutable (cannot be modified after creation). Lists use square brackets [] while tuples use parentheses (). Lists generally consume more memory than tuples.

3. How is memory managed in Python?

Python uses automatic memory management with a garbage collector. Objects are automatically deallocated when they are no longer referenced. Python's memory manager handles memory allocation and deallocation behind the scenes.

4. What are decorators in Python?

Decorators are a way to modify or enhance functions or classes without directly changing their source code. They use the @decorator_name syntax and are a form of metaprogramming, allowing you to wrap one function with another function.

5. Explain list comprehension in Python

List comprehension is a concise way to create lists based on existing lists or iterables. It follows the syntax: [expression for item in iterable if condition]. It's often more readable and faster than traditional for loops.

6. What is the Global Interpreter Lock (GIL)?

The GIL is a mutex that protects access to Python objects, preventing multiple native threads from executing Python bytecode simultaneously. This is specific to CPython and can impact multi-threaded performance in CPU-bound tasks.

7. What are Python generators?

Generators are functions that return an iterator using the yield keyword. They generate values on the fly and are memory efficient as they don't store all values in memory at once, instead generating them as needed.

8. How do you handle exceptions in Python?

Exceptions are handled using try-except blocks. You can catch specific exceptions or use a general except clause. The finally block is used for cleanup code that must run regardless of whether an exception occurred.

9. What is the difference between __init__ and __new__ in Python?

__new__ is a static method that creates and returns a new instance of the class, while __init__ initializes the created instance. __new__ is called before __init__ and is rarely overridden except in metaclasses.

10. Explain Python's inheritance and how to implement it

Python supports single and multiple inheritance. A class can inherit attributes and methods from one or more parent classes. It's implemented using the syntax: class Child(Parent). The super() function is used to call methods from the parent class.