0
Examples of "for" command in phyton
can anyone give me atleast some examples of for command in phyton, I don't completely understand it
2 ответов
+ 13
for number in range(0,10):
print(number)
#run this and I think you'll get the idea. "number" can be changed to any name (i is the most common name used) and you can replace range with lists or dictionaries
+ 3
for i in range(4):
i+=1
print(i)
#try this if you didn't understand mechanism. range(4) normally outputs 0 1 2 3 for takes this numbers as input variables which is named as i below. Basically it just makes the code run for every number that is in range. For an example this code adds 1 to every number that are in range 4. Finally it prints output: 1 2 3 4