Try this. I hope this will help u
languages = ["C", "C++", "Perl", "Python"]
for k in range(0,len(languages)):
print(languages[k-2])
and the output is :
Perl
Python
C
C++
In python the for loop function is (for k in x(start,stop,step)). Here x is your list or string variable and
start : Indicates where the for loop should start and the index starts from zero.
stop : Indicates where the for loop ends. It takes up to (n-1) elements.
For example :
for k in range(0,100):
it gives output till 99 from zero and if u want output of 100. U should mention like this :
n = 100
for k in range(n+1):
print k
the output is from 0 to 100. In this case for loop will take indexes (starts) from zero.
step : Indicates how many steps should do in for loop. By default step is one in for loop.
for example:
for k in range(0,10,1):
print k
#output is 0,1,2,3,4,5,6,7,8,9
for k in range(0,10,2):
print k
#output is 0,2,4,6,8
for k in range(0,10,3):
print k
#output is 0,3,6,9