1 Star 0 Fork 1

pish7/stdpython

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
range.py 719 Bytes
Copy Edit Raw Blame History
pish7 authored 2025-11-29 00:18 +08:00 . 整理代码
# range
a = list(range(0, 10)) # 包含0, 但不包含10
print(a) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = list(range(10)) # 起点默认为0
print(a) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = list(range(10, 0, -2)) # 指定起始值、终止值和负值步长
print(a) # [10, 8, 6, 4, 2]
squares = []
for value in range(1, 11):
squares.append(value)
print(squares) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
squares = []
for value in range(11):
squares.append(value)
print(squares) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# 将 range 转换为 list
numbers = list(range(1, 6))
print(numbers)
# range 的第三个参数用于指定步长
even_numbers = list(range(2, 11, 2))
print(even_numbers) # [2, 4, 6, 8, 10]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/pish7/stdpython.git
git@gitee.com:pish7/stdpython.git
pish7
stdpython
stdpython
master

Search