e-learning

Python - Loops

Abstract

A for loop tells Python to execute some statements once for each value in a list, a character string, or some other collection: "for each thing in this group, do these operations"

About This Material

This is a Hands-on Tutorial from the GTN which is usable either for individual self-study, or as a teaching material in a classroom.

Questions this will address

  • How can I make a program do many things?

Learning Objectives

  • Explain what for loops are normally used for.
  • Trace the execution of a simple (unnested) loop and correctly state the values of variables in each iteration.
  • Write for loops that use the Accumulator pattern to aggregate values.

Licence: Creative Commons Attribution 4.0 International

Keywords: Foundations of Data Science, jupyter-notebook

Target audience: Students

Resource type: e-learning

Version: 3

Status: Active

Prerequisites:

  • Python - Flow Control
  • Python - Lists & Strings & Dictionaries

Learning objectives:

  • Explain what for loops are normally used for.
  • Trace the execution of a simple (unnested) loop and correctly state the values of variables in each iteration.
  • Write for loops that use the Accumulator pattern to aggregate values.

Date modified: 2023-02-13

Date published: 2022-04-25

Authors: Bazante Sanders, Donny Vrins, Helena Rasche, The Carpentries

Contributors: Bazante Sanders, Donny Vrins, Helena Rasche, The Carpentries

Scientific topics: Software engineering


Activity log