for i in range(5): print(" anything.. ") What does i here depicts?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

for i in range(5): print(" anything.. ") What does i here depicts??

26th Jun 2016, 11:46 AM
Kanishk Gangwar
Kanishk Gangwar - avatar
7 Answers
+ 2
here i depicts a variable which will take a value starting from 1 and will continue till 5
26th Jun 2016, 11:55 AM
whoami k
whoami k - avatar
0
please explain more about your problem ! this code is Ok! and it prints 5 times "anything.."
26th Jun 2016, 11:53 AM
Reza
Reza - avatar
0
i represents the number of values in the list range(5), because range produces a list. range(5)==[0, 1, 2, 3, 4] if it were: poo=['blah', 'fork', 'winslow'] for i in poo: print('jackalope!') it would result in: >>> jackalope! jackalope! jackalope!
27th Jun 2016, 12:23 AM
Zak Waddle
Zak Waddle - avatar
0
but...: poo=['blah', 'fork', 'winslow'] for i in poo: print(i) would give you: >>> blah fork winslow please correct me if any part of this is wrong.
27th Jun 2016, 12:24 AM
Zak Waddle
Zak Waddle - avatar
0
i ranges from 0 to 4 in your problem.. i is nothing but a variable that will take these five values one by one starting with i=0..you could use any variable name in place of i..
7th Jul 2016, 11:19 AM
Saurav
Saurav - avatar
0
'i' is used as a counter. Each time the loop completes one round it's value will be increased by a default value of 1. You can give your own value by entering "for I in range(0,5,2)".This will increase the value the value of 'i' by 2 each time. You can also use 'i' within the loop to print members of a list. Hope this helps.
8th Jul 2016, 12:30 PM
Athreyan MKS
Athreyan MKS - avatar
0
Print(range(5))
8th May 2024, 12:58 AM
haris chandra
haris chandra - avatar