user18041
0
Q:

python iterration

n = 10 #n is end
s = 1 #s is start
p = 1 #p is step
for i in range(s,n+1,p):
  print(i,end=",")
#prints all numbers from s to n going up in p
#in our case it would print 1,2,3,4,5,6,7,8,9,10
1
>>> a = ['foo', 'bar', 'baz']
>>> for i in a:
...     print(i)
...
foo
bar
baz
1
for i = 1 to 10
    <loop body>
0

n = 5
while n > 0:
    print n
    n = n-1
print 'Blastoff!'
0
import numpy as np
# With array cycling
arr = np.array([1,2,3,4,5,6,7,8,9])

for i in range(len(arr)):
 # logic with iterator use (current logic replaces even numbers with zero)
    if arr[i] % 2 == 0: arr[i] = 0

print(arr)
# Output: [1, 0, 3, 0, 5, 0, 7, 0 , 9]
0

New to Communities?

Join the community