Getting Values or Index from List through Loop in Python.
In my opinion python is most easy computer language with most understandable syntax. It can be a good language for novice coders because of its readability and use of English language. Python goes beyond a basic web development. It can be used for Data Science, Machine learning, Data mining and many more.
Python uses same logic or concepts as other languages but there are some concepts that are not available in other programming languages e.g List, Tuple, Dictionary etc.
In this blog we will talk about Looping through these entities and getting values or index by looping through them. Lets get some overview of loop concept in python language(For Loop particularly).
For loop syntax:
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). “X” is used as variable, you can use different name for this variable. This variable work same as other variables in python or other languages.
Now let’s get our main topic, getting values or index of items in List, Tuple, Dictionary etc. Sometime it’s confusing when we want to get index of the items but we got values. Let’s get out of this confusion.
Think of the above example, what output will we get out this example. Yes, you are right the answer is values.
Output:
In the Loop we are iterating over the values that’s why we are getting the values. What if we want to get the index of the items of List.
Look the following example:
Now thing again of result. This time the result will be different. The result will be index this time. Remember that in programming language index start from zero “0”.
Output:
In above example we are iterating over the length of items, that’s why we are getting index of the items starting from zero “0” to one less than the items length.

