+ 1
I really do not get this loop stuff, please can anyone explain it in a better and understandable way
Looping in pyton
2 Answers
+ 1
looping is used to do something over and over again. potentally an infinite amount of times.
+ 1
Eg: you need to print something 1000 times.
Instead of doing:
print("Hi")
print("Hi")
print("Hi")
print("Hi")
...
1000 times, you could simply do:
for i in range(1000):
print("Hi")
As you see, the code is way shorter. Also, you can't write print a variable number of times, i.e. If you allow the user to enter a number and say hi that many times.