for Statement¶for character in 'Programming':
print(character, end=' ')
for loop, Python assigns the 'P' in 'Programming' to the target variable between keywords for and in.r' in 'Programming'), then executes the suite again. for Statement Flowchart¶
print’s end Keyword Argument¶print displays its argument(s), then moves the cursor to the next line. end:print(character, end=' ')
end is a keyword argument, but it's not a Python keyword. print’s sep Keyword Argument¶sep (short for separator) specifies the string that appears between the items that print displays. print(10, 20, 30, sep=', ')
for statement’s in keyword must be an iterable. for statement can take one item at a time. [ and ]). total = 0
for number in [2, -3, 0, 17, 9]:
total = total + number
total
range Function and Generators¶for counter in range(10):
print(counter, end=' ')
A logic error known as an off-by-one error occurs when you assume that range’s argument value is included in the generated sequence.
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 3 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.