Sollicitatievraag bij Capgemini

What is the difference between a list and a tuple in Python?

Antwoord op sollicitatievraag

Anoniem

14 mrt 2025

A list in Python is a mutable data structure, meaning we can modify, add, or remove elements after creation. It is defined using square brackets []. In contrast, a tuple is immutable, meaning once it is created, its elements cannot be changed. Tuples are defined using parentheses (). Because of this immutability, tuples are generally faster than lists and are often used for fixed collections of items where modification is not needed.