i mean nothing in Python, yes you heard it right i mean nothing. i is neither a function nor variables or keywords.
So what is i really?
i is a conventional variable just like var temp that is defined by users to store data. i is mostly used in loops for the execution of loops. This convention helps the programmers to write codes which can understand by other programmers.
Let’s take an example, Python program to find the sum of numbers from 1 to 10
sum = 0
for i in range(1, 11):
sum += i
print(f"The sum of numbers from 1 to 10 is: {sum}")
The output of the code is
The sum of numbers from 1 to 10 is: 55
In the above program, we have used i variable to iterate through the for loop. You can use any variables name like a,x or pixelcodepro, still the code will be executed.
Let’s change the i with a in the above code and see what’s is the output.
sum = 0
for a in range(1, 11):
sum += a
print(f"The sum of numbers from 1 to 10 is: {sum}")
The output of the code is
The sum of numbers from 1 to 10 is: 55