Python Interview: List vs Tuple - Key Differences

✅ Python Interview: List vs Tuple 💼 1️⃣ Are Lists and Tuples mutable?   Answer:   - List: ✅ Mutable — can be changed   - Tuple: ❌ Immutable — cannot be changed after creation  2️⃣ Which is faster in performance?   Answer:   Tuple is generally faster than List due to immutability and fixed size. 3️⃣ Can Lists and Tuples store different data types?   Answer:   ✅ Both can store mixed data types like ["Alice", 25, True] or ("Bob", 30, False) 4️⃣ Do Tuples take less memory than Lists?   Answer:   Yes, Tuples are more memory-efficient because they’re immutable and have a smaller memory footprint. 5️⃣ When should you use Tuple over List?   Answer:   Use Tuple when:   - Data should not change   - Used as keys in a dictionary   - Better performance is needed  6️⃣ Can a Tuple be used as a dictionary key?   Answer:   ✅ Yes — because it’s immutable   ❌ List cannot be used as a key (mutable, unhashable) 7️⃣ How do you convert between them?   Answer:   - tuple(my_list) → List to Tuple   - list(my_tuple) → Tuple to List  8️⃣ Do both support indexing and slicing?   Answer:   ✅ Yes — both support [0], [-1], [:2] style access 9️⃣ Can Tuples contain Lists?   Answer: ✅ Yes — but the tuple is immutable, not the list inside. 🔟 Which is better for function arguments?   Answer:   A tuple is often used to return multiple values from a function.   The list is better when the returned data is modified. Follow for more........................... #Dataanalyst #Python #Datascientist

To view or add a comment, sign in

Explore content categories