打印lis中字符串项的字符间隔

2024-10-01 00:22:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个列表,上面有一堆字符串。到目前为止,我似乎还不知道如何从第一个字符到第七个字符这样的间隔只打印字符。你知道吗

我试图解决这个问题:

wellDescribedList["TestName", "RandomString", "EvenMoreRandomString", .....]
someItem = 5    # for example the second item from the list [start, end]

print(wellDescribedList[someItem][0, 7])

Python指出[0,7]将导致TypeError,这在逻辑上不是我要查找的结果。你知道吗

如何在不使用任何循环(for、while等)的情况下解决此问题


Tags: the字符串from列表for间隔exampleitem