1、字符串切片
s = 'cjavapy_c_cjavapy_python'
print(s[::-1])
print(s[2:7])
2、列表切片
l = list(range(1,11))
print(l)
print(l[0:5])
print(l[:5])
print(l[5:11])
print(l[5:])
print(l[:])
print(l[::2])
print(l[::-1])
print(l[-1:-6:-1])
3、利用切片实现字符串加密及解密
str1="url=https://www.cjavapy.com"
print("原始内容:",str1)
if len(str1)%2==1:
str1=str1+" "
l2=len(str1)
else:
l2=len(str1)
str2=str1[::-2]
str3=str1[l2-2::-2]
print("截取内容一:",str2)
print("截取内容二:",str3)
result=""
for i in range(len(str2)):
result += str2[i]+str3[i]
print(result[::-1])