0

Please can someone explain loops (for), and range to me like a child

21st Feb 2022, 7:36 PM
Adedeji Qudus
Adedeji Qudus - avatar
3 Answers
+ 1
1- 'for' is used to iterate over a finite (list,dict,tuple,set ...)(iterable or generator) returning each element in their order on iterable: #example for i in [1,2,3,4]: # gets each element using 'i' local variable print(i) # stuff to do with each 'i' 2- range() is used to get a 'range' object generating values from start=0(default) to stop(non-default) with step=1(default) # example print(range(4))# prints __repr__ of 'range' object print(list(range(4))) # prints [0,1,2,3] print(list(range(0,10,2))) # prints [0,2,4,6,8] Notice that stop is not included in result and that all values can be changed # 'range' is best friend with 'for' for i in range(4): print(i) That's all (惻āˆ€ćƒ»)
21st Feb 2022, 9:06 PM
Ervis Meta
Ervis Meta - avatar
0
Thank you very much
21st Feb 2022, 9:19 PM
Adedeji Qudus
Adedeji Qudus - avatar
0
Was a pleasure (ļ½”ā€¢Ģ€į“—-)āœ§
21st Feb 2022, 9:20 PM
Ervis Meta
Ervis Meta - avatar