I'm newbie in python. I don't understand the output of following python program.
arr = []
for i in range(3):
arr.append(i * 2)
for arr[i] in arr:
print arr[i]
Output:
0
2
2 // Why also print 2??
Here, An array elements print twice time 2. This is really weird.
Please someone help me to clear my doubt. Why program print twice time 2?
arr[i]- i.e. -arr[2]as the loop variable! You want to dofor x in arr: print(x)for j in arr: print j? Not sure what you're trying to achieve by having arr[i] as the iterating value.