截取字符串

发布时间 2023-07-01 19:41:08作者: 胖豆芽
# 切片  步长写-1时,表反向输出
str_yuan = "运命重尊,然自其顺的余其,的做能己自做"
# 倒叙
str1 = str_yuan[::-1]
# 截取
start_index = str1.find("")
end_index = str1.find(",尊")
result = str1[start_index:end_index]

# 倒叙后的结果
print(str1)
# :做自己能做的,其余的顺其自然,尊重命运
# 截取的结果
print(result)
# :顺其自然