+ 3
Please help me understand this code
for i in range(5): print(“hello!”) Result: hello! hello! hello! hello! hello! Can Someone break down each component of this code and explain It to me, also explaining how It gives the result It does please. Thank you
15 odpowiedzi
+ 12
The for loop performs the specified functions (in our case, print ("hello")) for each element in the range from 0 to 5 (0, 1,2,3,4). Thus, we get the word "hello" 5 times.
+ 10
Do it:
for i in range(5):
print(i)
+ 9
In this case, yes
+ 7
Błack Jesus😣 that's not correct. In python, range() starts from 0 if you do not add a starting point argument.
The way it works:
for i in range(5):
#i will be 0,1,2,3,4 so 5 times
print("hello!")
#Output:
hello!
hello!
hello!
hello!
hello!
+ 6
Tanner No, it would be 3, 4
The 2nd argument is exclusive.
+ 3
Tanner no it would be 3,4
+ 3
Because for i in range(3,4) i will be 3 then 4
+ 2
but i got 5 hello,and i got this off the course for python.
+ 2
so range( 3, 5)
would be 3, 4, 5
+ 2
i tried it and why is i 4
+ 2
so range() is what defines i
+ 2
ok i get it now thank you guys so much
+ 2
FOR every entry of RANGE(5) (0, 1, 2, 3, 4)... Do the following...
In this case you PRINT the words "hello!" To the screen for each entry in range.
The variable "i" would be your identifying key for any iteration or the value itself depending on circumstance. In this instance you don't use it but it will hold the values of RANGE(5)