-2
str1 = ‘This is Pyhton’
print ("Slice of String : ", str1[1 : 4 : 1])
print ("Slice of String : ", str1[0 : -1 : 2])
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

It's an array slice. It means

str1[start:stop:step]

Takes str1[1 : 4 : 1], starting from character in position 1, not going past 4, by step 1.

print ("Slice of String : ", str1[0 : -1 : 2])

Means starting from character in position 0 (The first character), not going past the last character (position -1 is the last character since it goes cycle), by step 2.

Position:  0    1    2   3   4   5  6  7  8   9   10  11  12  13
String:    T    h    i   s       i  s     P   y   h   t   o   n
Position:  -14 -13  -12 -11 -10 -9 -8 -7 -6  -5  -4  -3  -2  -1
ALFA
  • 1,726
  • 1
  • 10
  • 19