【发布时间】:2021-11-15 09:24:40
【问题描述】:
text = "hi, hello! hello! I have a cat hello! the fire burns 88988° the planes are sooo fast" #Exmple string
print(len(text))
if(len(text) > 20):
#text = text[:-10]
t_len = len(text) +(-len(text) - 10)
text = text[:-t_len]
print(len(text))
print(text)
我尝试了几件事,但我需要的是,如果 len (string)> n 然后提取我并将最后 50 个字符保存在另一个变量中
【问题讨论】:
-
text[-50:]是最后 50 个字符。 -
“提取我”是什么意思
-
text[:-10]是 除了最后 10 个字符。 -
我想提取最后 50 个字符,这将删除最后 50 个字符。留下最后 50 个字符
标签: python python-3.x string text substring