The range's integers provide a repeat count in the first, and a position for slicing in the second:
S = 'test' for i in range(len(S)): # For repeat counts 0..3 S = S[1:] + S[:1] # Move front item to end print(S, end=' ') S = 'test' # from w w w . j a va 2 s . co m for i in range(len(S)): # For positions 0..3 X = S[i:] + S[:i] # Rear part + front part print(X, end=' ')
The second creates the same results as the first in a different order.
L = [1, 2, 3] for i in range(len(L)): X = L[i:] + L[:i] # Works on any sequence type print(X, end=' ')