so on. This is called as Reverse Indexing. Marks = [ , , , ] i = - while i >= - : print (Marks[i]) i = i + - Output Example The following table shows the working process of the above python coding 12th Computer Chapter - - Iteration i while i >= - print ( Marks[i] ) i = i + - - - >= - True Marks[- ] = - + (- ) = - - - >= - True Marks[- ] = - + (- ) = - - - >= - True Marks[- ] = - + (- ) = - - - >= - True Marks[- ] = - + (- ) = - - - >= - False -- -- . .
List Length The len() function in Python is used to find the length of a list. (i.e., the number of elements in a list). Usually, the len() function is used to set the upper limit in a loop to read all the elements of a list. If a list contains another list as an element, len() returns that inner list as a single element.
>>> MySubject = [“Tamil”, “English”, “Comp. Science”, “Maths”] >>> len(MySubject) Example :Accessing single element MySubject = ["Tamil", "English", "Comp. Science", "Maths"] i = while i < len(MySubject): print (MySubject[i]) i = i + Output Tamil English Comp. Science Maths Example : Program to display elements in a list using loop .
. Accessing elements using for loop In Python, the for loop is used to access all the elements in a list one by one. This is just like the for keyword in other programming language such as C++. Syntax: for in list: print ( ) 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary Here, represents the index value of each element in the list.
Python reads this “for” statement like English: “For (every) element in (the list of) list and print (the name of the) list items” Marks=[ , , , ,