基本语法:str(start:end:step)
注意事项: 1.区间范围左闭右开
2.start不写默认0
3.end不写默认无限最后
4.step为步长:step为正时,从左至右进行切片;step为负时,从右至左进行切片
#切片操作
s = 'abcdefg' print("切片操作的结果:",s[:1])
print("切片操作的结果:",s[::2])
print("切片操作的结果:",s[2:5])
print("切片操作的结果:",s[::-1]) #反转
运行结果如下: