Python 3.x Python 3:切分押韵

Python 3.x Python 3:切分押韵,python-3.x,computer-science,Python 3.x,Computer Science,通过将押韵歌词从起始索引分割到结束索引,分配带有“cow”的子歌词。给定程序的示例输出: 母牛 这就是你想要的: start_index = 4 end_index = 7 rhyme_lyric = 'The cow jumped over the moon.' sub_lyric = rhyme_lyric [start_index: end_index] print(sub_lyric) 这就是你需要的 start_index = 4 end_index = 7 rhyme_lyric

通过将押韵歌词从起始索引分割到结束索引,分配带有“cow”的子歌词。给定程序的示例输出:

母牛


这就是你想要的:

start_index = 4
end_index = 7
rhyme_lyric = 'The cow jumped over the moon.'
sub_lyric = rhyme_lyric [start_index: end_index]
print(sub_lyric)
这就是你需要的

start_index = 4
end_index = 7
rhyme_lyric = 'The cow jumped over the moon.'
sub_lyric = rhyme_lyric[start_index : end_index]
print(sub_lyric)

python中的字符串被视为列表和数组,其第i个字符可以作为
string[i]
访问。此外,
lyme\u lyric
包含单词cow,对其进行切片以提取“cow”。您可以在

上阅读有关切片的更多信息。我已经检查了这里给出的所有解决方案,并执行了简单的分析。 对我有效的解决方案是使用以下代码行:


sub\u lyric=lyme\u lyric[start\u index:end\u index]

不清楚您需要什么帮助。因此,并不是为OP提供完整的解决方案。它旨在帮助你理解你遇到的困难。
start_index = 4
end_index = 7
rhyme_lyric = 'The cow jumped over the moon.'
sub_lyric = rhyme_lyric[start_index : end_index]
print(sub_lyric)