Robotics & Artificial Intelligence
Find out one situation where lists are not suitable but the tuples are suitable.
Python Tuples
1 Like
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
2 Likes
Related Questions
Write a Python program to search an element in the list.
Write a Python program to generate the square of all the elements of a list.
Write a Python program to add all the elements of the list.
Write a program in Python to create a list of your classmates containing their names and roll numbers. Access the roll number of the student whose name is stored at 2nd index.