range in Python: The function can
If you have a little bit of Python worked, they are perhaps about the range function stumbled upon:
- The range function creates a list of Numbers that are often used in connection with for-loops.
- The Syntax of the range function is the Same: "range(start, stop, step) is actually, every Time"
- Instead of "start" but write the start number of the sequence. The Count then starts at this point.
- With "stop" you can set in turn, wherein the number of the function with the Count to stop. The number that is specified when "stop" is issued, however: If the last value is a 5 then enter, for example, a 4.
- With "step" select, in what steps will be counted. If you enter, so for example, here a 2, is always skipped a number.
- Tip: For a simple range function, you need not specify all parameters explicitly. If you use, for example, the function "range(5)", output the Numbers 0, 1, 2, 3, and 4. With the function "range(3, 6)" are output again to the Figures 3, 4 and 5. Finally, be output with the function "range(4, 10, 2)", for example, only the Numbers 4, 6 and 8.
- Note that all parameters must be integers and positive or negative can be.

What is the range function can?
Loops and range functions
So you can use the range function to work properly, you should pair this with a for loop.
- You write first for loop: "for i in range(...):" (without the quotation marks)
- Now you need to write button just under the loop with the tab to the right "print(i)".

Loops and range functions
xrange and range: what is the difference?
In addition to the range function in Python is also the xrange function. But where is the difference in these functions is?
- The normal range function creates a list that contains all the values.
- With the xrange function, however, an object is created that stores only the parameters Pane, and the numbers on the request generated.
- The xrange function is so minimally faster, than the normal range function.
- The Syntax is almost the Same: "xrange(start, stop, step)". You only need to add a "x" at the beginning of the function.
More tips to Python in our CHIP counselors
Tip: On our topic page for the Python programming language, you can find more Tutorials about programming. There we will show you for example the most important Standard commands for Python beginners.
