相关疑难解决方法(0)

Python的范围功能如何工作?

如果我写

for i in range(5):
      print i
Run Code Online (Sandbox Code Playgroud)

然后它给出0,1,2,3,4这
是否意味着Python同时为0分配0,1,2,3,4?
但是,如果我写道:

for i in range(5):
      a=i+1
Run Code Online (Sandbox Code Playgroud)

然后我打电话给a,它只给5
但是如果我加''打印''它给出1,2,3,4,5
所以我的问题是这里的区别是什么?
是字符串还是列表还是其他什么?

或者也许任何人都可以帮助我理清:

for l in range(5):
    #vs,fs,rs are all m*n matrixs,got initial values in,i.e vs[0],fs[0],rs[0] are known
    #want use this foor loop to update them
    vs[l+1]=vs[l]+fs[l]
    fs[l+1]=((rs[l]-re[l])
    rs[l+1]=rs[l]+vs[l]
#then this code gives vs,fs,rs
Run Code Online (Sandbox Code Playgroud)

如果我运行这种代码,那么只有当l = 5时我才能得到答案
我怎样才能让它们开始循环?

即l = 0得到vs [1],fs [1],rs [1]的值,
则l = 1得到vs [2],rs [2],fs [2] ......的值等等.
但是python给出了不同的fs数组,vs,rs,对应不同的l值

我怎么能把它们做成一件?

python for-loop range

23
推荐指数
4
解决办法
13万
查看次数

标签 统计

for-loop ×1

python ×1

range ×1