मराठी
तामिळनाडू बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान इयत्ता १२

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

Advertisements
Advertisements

प्रश्न

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

थोडक्यात उत्तर

उत्तर

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 2: Data Abstraction - Evaluation [पृष्ठ १९]

APPEARS IN

सामाचीर कलवी Computer Science [English] Class 12 TN Board
पाठ 2 Data Abstraction
Evaluation | Q 4. | पृष्ठ १९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×