+ 1
s='12345'. s[::-2]='531', s[:1:-2]='53',s[:4:-2] or s[:-1:-2] or s[1:4:-2]=' '. How do we get these outputs
2 ответов
+ 1
print( s[a:b:+-c])
it works like (
for ( k= a; k<b; k= k+c ){
print(s[k]) } # using C for - loop
or for negative step (decrement)
for (k=a; k>b ; k = k - c){}
so s[:-1:-2] is same as s[-1:-1:-2] , or s[4:4:-2]
note the index -1 is the last element in py-list.