In Python, range(start, stop + 1, step)
can be used like Matlab's start:step:stop
command. Unlike Matlab's functionality, however, range
only works when start
, step
, and stop
are all integers. If you want a parallel function that works with floating-point values, try the arange
command from numpy
:
import numpy as np
with open('numbers.txt', 'w') as handle:
for n in np.arange(1, 5, 0.1):
handle.write('{}
'.format(n))
Keep in mind that, unlike Matlab, range
and np.arange
both expect their arguments in the order start
, stop
, then step
. Also keep in mind that, unlike the Matlab syntax, range
and np.arange
both stop as soon as the current value is greater than or equal to the stop value.
http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…