487,203 views
40 votes
40 votes
Is index and i the same in python. For example when i say:

for i in range....

am i referring to index (so is index short form of i)

User Miwako
by
3.1k points

2 Answers

23 votes
23 votes
????????????????????
User Jonathan Bates
by
2.9k points
13 votes
13 votes

Answer:

In a for loop in Python, the variable i is used to represent the current iteration or index of the loop. It is a common convention to use i as the loop variable, but you can use any variable name you like. For example, the following code is equivalent to the code you provided:

for index in range(...):

# code here

In this case, index is the loop variable and it will take on the values of the indices in the range() function as the loop iterates.

So, in short, i and index are not the same thing, but they can be used to represent the same thing (the current index of a loop) depending on the variable name you choose to use.

User Bahaa Hany
by
3.0k points