English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

What is a List? Why List can be called as Pairs. Explain with a suitable example? - Computer Science

Advertisements
Advertisements

Question

What is a List? Why List can be called as Pairs. Explain with a suitable example?

Answer in Brief

Solution

The list is constructed by placing expressions within square brackets separated by commas. Example for List is [10, 20],
The elements of a list can be accessed in two ways. The first way is via our familiar method of multiple assignments, which unpacks a list into its elements and binds each element to a different name.
1st: = [10, 20]
x, y: = 1st
In the above example, x will become 10 and y will become 20.
A second method for accessing the elements in a list is by the element selection operator, also expressed using square brackets. Unlike a list literal, a square – brackets expression directly following another expression does not evaluate a list value but instead selects an element from the value of the preceding expression.
1st [0]
10
1st [1]
20
In both the example mentioned above mathematically we can represent a list similar to a set.
1st [(0, 10), (1, 20)] – where

Any way of bundling two values together into one can be considered as a pair. Lists are a common method to do so. Therefore List can be called a pair.

shaalaa.com
Lists, Tuples
  Is there an error in this question or solution?
Chapter 2: Data Abstraction - Evaluation [Page 20]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 12 TN Board
Chapter 2 Data Abstraction
Evaluation | Q 2. | Page 20
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×