How does the following code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How does the following code work?

for i in range(5): print("hello")

28th Aug 2016, 3:14 PM
harkirat singh
harkirat singh - avatar
6 Answers
+ 1
"i" is just a variable, so yes. It can be substituted for any other string you'd like.
29th Aug 2016, 8:47 AM
Xavi
Xavi - avatar
+ 1
Python is a language where you don't have to define 'i' before using it in the for loop. So assuming you aren't defining any other variable, you can substitute 'i' with any variable that is not critical to the program logic.
29th Aug 2016, 10:43 AM
Nakul Dumblekar
Nakul Dumblekar - avatar
0
easy print works like this...print ("Hello World ") then you run it and I should say the following..... Hello World
28th Aug 2016, 4:20 PM
BlazingPlayer30
0
Still confused about how the for i in range(argument) function works
29th Aug 2016, 3:06 AM
harkirat singh
harkirat singh - avatar
0
I understand the range part properly Can the i be substituted with any other string or does it have to be i?
29th Aug 2016, 3:48 AM
harkirat singh
harkirat singh - avatar
0
Thanks everyone ☺
29th Aug 2016, 10:50 AM
harkirat singh
harkirat singh - avatar