KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Find out one situation where lists are not suitable but the tuples are suitable.

Python Tuples

3 Likes

Answer

Lists are not suitable when the data is fixed and should not be changed during program execution. In such cases, tuples are suitable because they are immutable (elements cannot be modified, added, or removed).

Example: Storing the days of the week.

days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")

Benefit: A tuple prevents accidental changes, making the data safer and more reliable (also slightly more memory-efficient than a list).

Answered By

3 Likes


Related Questions