How do I use for loops in Python?

For loops and other loops are a very powerful tool in programming. Lets say you have a program that prints "hello" onto the screen and you want to print it 5 times instead, one solution is copy that code 5 times. What happens if you want to print "hello" 100 or 1000 times? One way of doing this is using a for loop. (show and explain syntax on code editor)
There are many other uses of for loops, for example going through each item in a list or each character in a string in order and doing something with those items.

RK

Related Python Mentoring answers

All answers ▸

How does a for loop work in Python?


how to compute the factorial of a number.


How do I check if a number is prime using a python program?


[Exam style] Python is an interpreted language. Explain what this means and how interpreted languages differ from compiled languages.