Did my python ide break or something?
import sys
i = 0
sample = ("this", "is", "Annoying!")
for line in sample:
print i, line
i + 1
Now gives me…
0 this 0 is 0 Annoying!
I THOUGHT, it would give me:
1 this 2 is 3 Annoying
I had other scripts that I was working on and it they all just broke – they all have the same line number when they print numerous iterations using the for statement – can someone PLEASE tell me what the heck is going on – very frustrated lol… did Python break? Do I need sleep? What is wrong here?
While the other answers are correct, this is how you usually do this in python:
The
enumeratefunction does exactly what you want: Iterating through your tuple, while at the same time giving you (line) numbers.