如何在一定范围内得到数字的倍数。
For example:
For 10 in range(100):
returns => [10,20,30,40,50,60,70,80,90,100]
For 9 in range(100):
returns => [9,18,27,36,45,54,63,72,81,90,99]
For 7 in range(100):
returns => [7,14,21,28,35,42,49,56,63,70,77,84,91,98]
答案 0 :(得分:1)
您可以将正确的start, stop and step
参数传递给range()
函数。
>>> print(list(range(0, 100, 10)))
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
>>> print(list(range(0, 100, 9)))
[0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99]
>>> print(list(range(0, 100, 7)))
[0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]
答案 1 :(得分:0)
范围(分钟(含),最大(不包括),倍数)
示例:
>>> range(0, 10, 2)
[0, 2, 4, 6, 8]
2的倍数是> = 0且< 10。