What is the difference between a list and a tuple in Python? What is the difference between == and is in Python? What are Python decorators?
💡 Model Answer
A list is a mutable, ordered collection that can be modified after creation (append, pop, etc.), whereas a tuple is immutable; once created, its elements cannot be changed. This immutability makes tuples hashable, allowing them to be used as dictionary keys or set members, while lists cannot. Lists are typically used when data may change; tuples are used for fixed collections or to signal that the data should not be altered.
The == operator compares the values of two objects for equality, performing element‑wise comparison for containers. The is operator checks identity, determining whether two references point to the exact same object in memory. For example, a = [1,2]; b = [1,2]; a == b is True, but a is b is False. However, small integers and interned strings may have a is True due to caching.
Python decorators are higher‑order functions that modify or extend the behavior of other functions or methods without changing their code. A decorator takes a function as input and returns a new function, often wrapping the original. Common uses include logging, authentication, caching, and timing. The syntax @decorator above a function definition applies the decorator automatically. Decorators can be simple or accept arguments, enabling reusable, composable enhancements.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500