Last week, we learned how to use the conditional structure to write the program of Guess the Number. However, you must have noticed that this mode is indeed too simple since we can only make one guess. If we can guess for multiple times, the probability of guessing right result would be much bigger. To allow guessing for multiple times, we need to use the loop structure. The function of range() can be used to to generate a group of regular data. If you need an integer sequence, especially an arithmetic sequence, you can use the built-in function range() in Python . When use, the function of range() may be followed by different arguments, maybe one, two or three arguments. Let's look at this. If there are three arguments, the first argument represents the starting value, as 0 by default, the second argument represents the end value, which is not included, the third argument is "step", as 1 by default. If you use the default step of 1 , it may be written like this. What's more, if the step is 1, and the default starting value of start 0 is also applied, we can write it like this, with only one argument. The return value of the function range () is a "range" object, also a built-in sequence in Python. Range objects are iterable. Let's look at an actual instance. To make it easier, we convert them into lists with the list() function. First, range(3, 11, 2). What does it mean? It means the starting value is 3, and the end value is 11. This value is not included. The step length is 2. It's actually 3-10. Then, this value starts with 3, next value is 5, followed by 7, and then by 9. It should generate 4 values: 3 5 7 9, Let's see. The results are actually like that. Next example. It uses the default step 1, so it generates a series of integers from 3 to 10. In this example, the starting value is 0 and the step length is default 1, so it leads to a group of integers from 0 to 10. Well how many values can the range() function generate in the end? Let's look at the regularity. Suppoer the step length is 1, we know 8 values can be generated in the end with this form. The form below will lead to 11 numbers. How are they generated? You guys may have probably disocvered that if the default step length is 1, it's indeed the difference of argument values. We should bear this regularity in mind. It's cleverly designed. The range() function ins Python 3 is similar to the xrange () function in Python 2, the function returns a range object similar to a generator. What is a generator then? It utilizes the mechanism of lazy evaluation, which means it does not generate all the numbers at one time. By contrast, after it calculates an item, it generates the item, that's to say it only generates what it needs. It's quite suitable for big data amount processing, similar to a lazy list. The range() function is frequently used in looping, especially suitable for use in conjunction with a "for" statement. We'll see a lot of such instances later.