str = 'abcdefg'

str[首:尾:步长】 步长为负数的话是倒着取

1 str = 'abcdef'
2 a1 = str[0:4:2]
3 print(a1)   #ac
4 a2 = str[-1:1:-2]
5 print(a2)  #fd

 

相关文章: