MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is a tuple?
A
A data value which can be modified.
B
A data value which cannot be modified.
C
An immutable data structure that contains related elements.
D
A data structure that can only hold 3 elements.
Explanation: 

Detailed explanation-1: -Tuples are almost identical to lists, so they contain an ordered collection of elements, except for one property: they are immutable. We would use tuples if we needed a data structure that, once created, cannot be modified anymore. Furthermore, tuples can be used as dictionary keys if all the elements are immutable.

Detailed explanation-2: -Tuples are immutable, and usually contain a heterogeneous sequence of elements that are accessed via unpacking (see later in this section) or indexing (or even by attribute in the case of named tuples). Lists are mutable, and their elements are usually homogeneous and are accessed by iterating over the list.

Detailed explanation-3: -Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. A tuple is a collection which is ordered and unchangeable.

Detailed explanation-4: -We often call lists mutable (meaning they can be changed) and tuples immutable (meaning they cannot be changed).

Detailed explanation-5: -The basic difference between a list and a tuple is that lists are mutable in nature whereas, tuples are immutable.

There is 1 question to complete.