📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 138question

LISTS, TUPLES, SETS AND DICTIONARY

Chapter 3: 4 · COMPUTER SCIENCE

LISTS, TUPLES, SETS AND DICTIONARY 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary Marks = [ , , , ] Fruits = [“Apple”, “Orange”, “Mango”, “Banana”] MyList = [ ] Example In the above example, the list Marks has four integer elements; second list Fruits has four string elements; third is an empty list. The elements of a list need not be homogenous type of data. The following list contains multiple type elements. Mylist = [ “Welcome”, .

, , [ , , ] ] In the above example, Mylist contains another list as an element. This type of list is known as “Nested List”. Nested list is a list containing another list as an element. .

. Accessing List elements Python assigns an automatic index value for each element of a list begins with zero. Index value can be used to access an element in a list. In python, index value is an integer number which can be positive or negative.

Marks = [ , , , ] Marks Index (Positive) IndexNegative) - - - - Example Positive value of index counts from the beginning of the list and negative value means counting backward from end of the list (i.e. in reverse order). To access an element from a list, write the name of the list, followed by the index of the element enclosed within square brackets. Syntax: = [E1, E2, E3 …… En] print ( [index of a element]) 12th Computer Chapter - - >>> Marks = [ , , , ] >>> print (Marks[ ]) Example (Accessing single element): In the above example, print command prints as output, as the index of is zero.

>>> Marks = [ , , , ] >>> print (Marks[- ]) Example: Accessing elements in revevrse order A negative index can be used to access an element in reverse order. Note (i) Accessing all elements of a list Loops are used to access all elements from a list. The initial value of the loop must be zero. Zero is

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →