[英]Using list slicing and “+” operator how this work?
S=len(s)
i=0
while i<S:
fwd=s[i:]+s[1:i]
print(fwd)
i+=1
I want to know the working of fwd = s[i:]+s[1:i]
我想知道 fwd = s[i:]+s[1:i] 的工作原理
lets say that i = 2 and s = [0, 1, 2, 3, 4, 5].假设 i = 2 和 s = [0, 1, 2, 3, 4, 5]。 first it does s[2:](2, 3, 4, 5) + s1:2.
首先它执行 s[2:](2, 3, 4, 5) + s1:2。 then its [2, 3, 4] + [1] = [2, 3, 4, 1]
那么它的 [2, 3, 4] + [1] = [2, 3, 4, 1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.