Teach Yourself VISUALLY Python by Hart-Davis Ted;Hart-Davis Guy; & Ted Hart-Davis
Author:Hart-Davis, Ted;Hart-Davis, Guy; & Ted Hart-Davis [Hart-Davis, Guy & Hart-Davis, Ted]
Language: eng
Format: epub
Publisher: John Wiley & Sons, Incorporated
Published: 2022-07-27T00:00:00+00:00
Using the range() Function to Create a Numeric for Loop
When you need to loop through a sequence of nonsequential numbers, you can put them in a set and loop through the set. For example, the following for loop works through the numbers 4, 7, and 11 in a set:
for num in (4, 7, 11):
print(num)
This approach works fine, and you can use it for sequential numbers as well if you want â for example, for num in (1, 2, 3). But when you have many sequential numbers, using Pythonâs range() function is a better solution.
In the following example, the first line creates the variable r1 and uses the range() function to assign to it a range of 20 items. The second line creates the variable num and uses it in a for loop that iterates through r1. The third line, indented four spaces as usual, simply prints the current value of num.
r1 = range(20)
for num in r1:
print(num)
This example outputs 20 numbers, starting with 0 and ending with 19.
0
1
â¦
19
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Data Forecasting and Segmentation Using Microsoft Excel by Fernando Roque(2698)
PostgreSQL 14 Administration Cookbook by Simon Riggs(2227)
Cloud Auditing Best Practices: Perform Security and IT Audits across AWS, Azure, and GCP by building effective cloud auditing plans by Shinesa Cambric Michael Ratemo(1792)
Architects of Intelligence_The Truth About AI From the People Building It by Martin Ford(1248)
In-Memory Analytics with Apache Arrow: Perform fast and efficient data analytics on both flat and hierarchical structured data by Matthew Topol(1046)
Mastering Azure Virtual Desktop: The Ultimate Guide to the Implementation and Management of Azure Virtual Desktop by Ryan Mangan(1028)
Automated Machine Learning in Action by Qingquan Song Haifeng Jin Xia Hu(911)
Python GUI Programming with Tkinter, 2nd edition by Alan D. Moore(882)
Ansible for Real-Life Automation - A complete Ansible handbook filled with practical IT automation use cases (2022) by Packt(752)
Learn Wireshark - A definitive guide to expertly analyzing protocols and troubleshooting networks using Wireshark - 2nd Edition (2022) by Packt(749)
Data Engineering with Scala and Spark by Eric Tome Rupam Bhattacharjee David Radford(430)
Introduction to Algorithms, Fourth Edition by unknow(384)
ABAP Development for SAP HANA by Unknown(368)
Automated Machine Learning in Action by Qingquan Song & Haifeng Jin & Xia Hu(311)
Kubernetes Secrets Handbook by Emmanouil Gkatziouras | Rom Adams | Chen Xi(292)
The AWK Programming Language by Aho Alfred V. Kernighan Brian W. Weinberger Peter J. & Brian W. Kernighan & Peter J. Weinberger(282)
Asynchronous Programming in Rust by Carl Fredrik Samson;(271)
Learn Enough Developer Tools to Be Dangerous: Git Version Control, Command Line, and Text Editors Essentials by Michael Hartl(261)
Machine Learning for Imbalanced Data by Kumar Abhishek Dr. Mounir Abdelaziz(259)
