Python for loop , Python range function | Just enough Python

Veröffentlicht am: 23 September 2019
auf dem Kanal: Ajay Tech
79
1

Range function is a built-in function to generate a sequence of numbers. For example, the following will generate a sequence of numbers from 0 to 10

numbers = range(10)

How do you extract these numbers though ? For that you need some kind of an iterator. An iterator is something which can go over a sequence. That is where the for loop comes in. We will see some more examples of the range ( ) function in the next section.


for loop
The syntax for for loop is just as simple as the while loop. It is specifically designed for going over sequences – like a range for example.

for number in numbers :
print ( number )
1
2
3
4
5
6
7
8
9
10

This is consuming a lot of vertical space, right ? By default the print statement always ends with a new line statement ( escape character ‘\n’ ). If you do not want that, you can specify a specific character that the print statement should end with. For example, if we want the print statement to end with a space, do this.

1
2
for number in numbers :
print ( number , end=" ")
1 2 3 4 5 6 7 8 9 10
Ranges are not the only examples of sequences in Python. There are many more examples like Python Lists, Python Strings, Python Tuples, Python Dictionary, Python sets etc. We will see examples of these in the upcoming sections.
https://ajaytech.co/python-loops/#ran...
https://ajaytech.co/python-loops/#for...


Auf dieser Seite können Sie das Online-Video Python for loop , Python range function | Just enough Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Ajay Tech 23 September 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 79 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!