通过将 rhyme_lyric 从 start_index 切片到 end_index 来为 sub_lyric 分配 ‘cow’。给定程序的示例输出:
奶牛
start_index = 4
end_index = 7
rhyme_lyric = 'The cow jumped over the moon.'
sub_lyric = rhyme_lyric''' Your solution goes here '''
print(sub_lyric)
原文由 Jexler Caranto 发布,翻译遵循 CC BY-SA 4.0 许可协议
我一直在检查这里给出的所有解决方案并进行了简单的分析。对我有用的解决方案是使用以下代码行:
sub_lyric = rhyme_lyric[start_index:end_index]