Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

How to use for Loop in Python, Lecture notes of Computer Programming

Python for loop iterate over the sequences. It repeats the piece of code n number of times. Consider the following flowchart of for loop.

Typology: Lecture notes

2021/2022

Available from 10/27/2022

tantan-bernabe
tantan-bernabe 🇵🇭

5 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Program Tutorial
University of the Philippines
How to use for loop in Python
Python for loop iterate over the sequences. It repeats the piece of code n number of times. Consider the
following flowchart of for loop.
Flowchart
pf3
pf4

Partial preview of the text

Download How to use for Loop in Python and more Lecture notes Computer Programming in PDF only on Docsity!

Python Program Tutorial University of the Philippines How to use for loop in Python Python for loop iterate over the sequences. It repeats the piece of code n number of times. Consider the following flowchart of for loop. Flowchart

Python for loop can be used in two ways.

  • Using Sequence
  • Using range() function Using Sequence Sequences are called lists, sets, strings, tuples and dictionaries in Python. A for loop can be used to extract the elements of a sequence. Below is the loop syntax. Let's understand the following example. Example: 1 Output: Example: 2

Example - 2 Traverse the List element using range() function Output: Explanation: The len() function returns the length of the list. The range() got the number of elements in the list and printed its elements.