concept range() in category python

appears as: rge()
Tiny Python Projects: Learn coding and testing with puzzles and games

This is an excerpt from Manning's book Tiny Python Projects: Learn coding and testing with puzzles and games.

Let’s talk just a bit more about list comprehensions. As an example, we can generate a list of the squared values of the numbers 1 through 4 by using the range() function to get the numbers from a starting number to an ending number (not inclusive). In the REPL, we must use the list() function to force the production of the values, but usually your code won’t need to do this:

Figure 11.7 The map() function will call the verse() function with each element produced by the range() function. It’s functions all the way down.
  • Use the range() function
  • Hello World! Third Edition

    This is an excerpt from Manning's book Hello World! Third Edition.

    Luckily, there’s a shortcut. The range() function lets you enter just the starting and ending values, and it creates all the values in between for you. The next listing uses the range() function in the multiplication table example.

    Listing 8.4. A loop using range()
    for looper in range(1, 5):
        print(looper, "times 8 =", looper * 8)