Python Language Loops

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

As one of the most basic functions in programming, loops are an important piece to nearly every programming language. Loops enable developers to set certain portions of their code to repeat through a number of loops which are referred to as iterations. This topic covers using multiple types of loops and applications of loops in Python.

Syntax

  • while <boolean expression>:
  • for <variable> in <iterable>:
  • for <variable> in range(<number>):
  • for <variable> in range(<start_number>, <end_number>):
  • for <variable> in range(<start_number>, <end_number>, <step_size>):
  • for i, <variable> in enumerate(<iterable>): # with index i
  • for <variable1>, <variable2> in zip(<iterable1>, <iterable2>):

Parameters

ParameterDetails
boolean expressionexpression that can be evaluated in a boolean context, e.g. x < 10
variablevariable name for the current element from the iterable
iterableanything that implements iterations


Got any Python Language Question?