Application of reverse Python list slice interval specified output segment output

= S 'ABCDEFG'
# Returns a string from the starting position to the slice at index position 2 of the
print (s [: 3]) # output 'ABC'

# returned from the third index position to the end of the string sections
print (s [3:]) # output 'DEFG'

# string in reverse output
print (s [:: - 1] ) # output 'gfedcba'

# output interval from a start position of a character string of
print (s [:: 2] ) output # 'aceg'
Print (Range (10) [:: 2]) the even #: [0, 2, 4, 6, 8]

# they can also be used in combination with each other.
# 6 from the index position to index position 2, a character spacing reverse
print (s [6: 2: -2]) # output 'ge'

Guess you like

Origin www.cnblogs.com/aixiao07/p/11258712.html