我有以下代码:
def steps(low, hi, n):
rn = range(n)
newrn = rn
print rn #print 1
for x in rn[:]:
print x
newrn[x] = float(x)/n
diff = hi - low
print newrn
print rn #print 2
for y in rn[:]:
print y
rn.insert(y, (newrn[y] * diff) + low)
return rn
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我的第一次打印返回[0,1,2],但我的第二次打印返回[0,.333,.666].为什么变化?我只改变了newrn,但是也变了.这使我在尝试运行rn.insert行时得到'list indices must be integer not float'错误.
任何帮助?