July 2017
Beginner to intermediate
420 pages
10h 56m
English
The last concept I want to cover in our Python basics is looping, and we saw a couple of examples of this already, but let's just do another one:
for x in range(10): print (x),
The output of the previous code is as follows:
0 1 2 3 4 5 6 7 8 9
For example, we can use this range operator to automatically define a list of numbers in the range. So if we say for x in range(10), range 10 will produce a list of 0 through 9, and by saying for x in that list, we will iterate through every individual entry in that list and print it out. Again, the comma after the print statement says don't give me a new line, just keep on going. So the output of this ends up being all the elements of that list printed next to each other.
To do something ...
Read now
Unlock full access