Computer Science
Answer
Similarities:
Both tuples and lists maintain the order of elements.
Both support indexing and slicing to access and manipulate subsets of their elements.
Both can store elements of different data types, including numbers, strings, and other objects.
Both tuples and lists can be iterated over using loops.
Differences:
Tuples are immutable, while lists are mutable.
Tuples are enclosed in parentheses (), while lists are enclosed in square brackets [].
Tuples use less memory whereas lists use more memory.
We can use tuples in dictionary as a key but it is not possible with lists.
We cannot sort a tuple but in a list we can sort by calling "list.sort()" method.
We cannot remove an element in a tuple but in list we can remove an element.
We cannot replace an element in a tuple but we can replace in a list.
Related Questions
Assertion (A): clear() method removes all elements from the dictionary.
Reasoning (R): len() function cannot be used to find the length of a dictionary.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
What advantages do tuples have over lists?
What is a key-value pair in dictionary?
What are the differences between tuple and dictionary?