[0,1]的间隔分区

问题描述 投票:-1回答:1

Hey,我想在Python 3中将[0,1]划分为长度为0.05的相等分区。

python python-3.x partitioning partition
1个回答
0
投票

列表理解+ range()

result = [x / 100 for x in range(0, 100, 5)]

输出

[0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]
© www.soinside.com 2019 - 2024. All rights reserved.