for in range()
时间: 2024-01-17 10:52:28 浏览: 63
The "for in range()" statement is used in Python to create a loop that iterates a specific number of times. The "range()" function returns a sequence of numbers starting from 0 (by default) and incrementing by 1 until the specified number (not inclusive) is reached.
The basic syntax for the "for in range()" statement is:
```
for variable in range(start, stop, step):
# code block to be executed
```
where:
- "variable" is a variable that takes on the value of each item in the sequence.
- "start" is the starting number of the sequence (inclusive).
- "stop" is the ending number of the sequence (exclusive).
- "step" is the amount by which the sequence increments (default is 1).
For example, the following code will print the numbers from 0 to 9:
```
for i in range(10):
print(i)
```
Output:
```
0
1
2
3
4
5
6
7
8
9
```
阅读全文