Python IndexError: list index out of range for loop
Question:
So i got this error and i can’t figure it out why.
Can you explain it to me?
enter image description here
Answers:
you have to use for loop in specific range: make changes your for loop like…
tab = [1,3,4,6,7,6]
def is77():
for i in range(len(tab)):
print(tab[i])
is77()
You have to use def like this in python:
tab = [1,3,4,6,7,6]
def is77():
for i in tab:
print(i)
is77()
There are two ways you could fix that.
tab = [1,3,4,6,7,6]
def is77():
for i in tab:
print(i)
is77()
or
tab = [1,3,4,6,7,6]
def is77():
for i in range(len(tab)):
print(tab[i])
is77()
So i got this error and i can’t figure it out why.
Can you explain it to me?
enter image description here
you have to use for loop in specific range: make changes your for loop like…
tab = [1,3,4,6,7,6]
def is77():
for i in range(len(tab)):
print(tab[i])
is77()
You have to use def like this in python:
tab = [1,3,4,6,7,6]
def is77():
for i in tab:
print(i)
is77()
There are two ways you could fix that.
tab = [1,3,4,6,7,6]
def is77():
for i in tab:
print(i)
is77()
or
tab = [1,3,4,6,7,6]
def is77():
for i in range(len(tab)):
print(tab[i])
is77()