OneBite.Dev - Coding blog in a bite size

do a for loop in python

Code snippet on how to do a for loop in python

  for i in range(10): 
      print(i)

This code will print out the numbers from 0 to 9. The keyword “for” tells Python to start looping. The variable “i” is used to store each item from the “range” sequence. The “range” in this case is the numbers from 0 to 9. The keyword “in” tells Python to loop through the range. The colon ”:” at the end of the syntax indicates the start of the loop. Inside the loop, Python will execute the code that is indented. In this example, it will print out the value of “i”. After the loop is done, Python will continue with the next line of code and ignore any code that is not indented.

python