假设我们有一个长字符串,例如:
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