Ie our sum from 1 to n the range funcon rangeijk in

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ay! Itera\ng over the elements in a list for VARIABLE in LIST EXPRESSION: BLOCK <next statement> •  The for construct iterates over list elements, characters in strings, and other kinds of sequences (we’ll see some later) 7 13 ­09 ­23 Itera\ng over the elements in a list for VARIABLE in LIST EXPRESSION: BLOCK <next statement> •  for works for anything that can be iterated over (in Python, these are called iterables) •  At each itera\on of the loop, the variable takes the value of the next element in the list Itera\ng over the elements in a list Prints the grades higher than 85 Prints the grades below 80% of the highest Range Func\on and For Loops •  What if you want your loop to iterate over a range of numbers? •  ie. Our sum from 1 to N •  The range func\on range([i],j,[k]) in Python returns a sequence o...
View Full Document

This document was uploaded on 03/02/2014.

Ask a homework question - tutors are online