1An iterator is an object that can be iterated upon, meaning that you can traverse through all the values.
2#EXAMPLE OF ITERATOR
3nums=[2,3,4,5,6,7]
4it=iter(nums)
5print(it.__next__())
6for i in it:
7 print(i)
1import numpy as np
2# With array cycling
3arr = np.array([1,2,3,4,5,6,7,8,9])
4
5for i in range(len(arr)):
6 # logic with iterator use (current logic replaces even numbers with zero)
7 if arr[i] % 2 == 0: arr[i] = 0
8
9print(arr)
10# Output: [1, 0, 3, 0, 5, 0, 7, 0 , 9]
11
1
2def iter(times):
3 it = 1
4 for i in range(times):
5 its = it * 2
6 it = its
7 return it
8
9while True:
10 print()
11 print(iter(int(input("how many iteration? : "))))
12