【发布时间】:2019-12-24 01:25:11
【问题描述】:
假设我们有一个长字符串,例如:
s = "The long-string instrument is a musical instrument in which the string is of such a length that the fundamental transverse wave is below what a person can hear as a tone."
现在,我们都知道如何根据索引从这个字符串中提取字母了:
z = s[18:26]
print(z)
strument
但是有什么办法,我可以如何将这个索引分配给一个变量,然后根据这个变量对列表进行子集化?它应该看起来像这样:
z = [18:26]
print(s.z)
strument
【问题讨论】:
-
我在stackoverflow.com/questions/3911483/… 中添加了一个关于使用numpy 的
s_的答案,我认为这可能会更好地回答您的问题。我无法发布它,因为这个问题很快就结束了。