假设我们有一个长字符串,例如:
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
你要找的是slice objects:
相关问题 更多 >
编程相关推荐