English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

What are the different ways to access the elements of a list? Give example. - Computer Science

Advertisements
Advertisements

Question

What are the different ways to access the elements of a list? Give example.

Answer in Brief

Solution

List is constructed by placing expressions within square brackets separated by commas. An 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–bracket 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

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

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×