【发布时间】:2026-01-24 01:35:02
【问题描述】:
在 python 中,我想以这样一种方式对列表中的字符串进行切片,即必须删除/拼接出该列表中的前几个字符。
a=['hello', 'things', 'becoming', 'expensive']
如何从列表中的每个字符串中删除前两个字符以获取输出
['llo', 'ings', 'coming', 'pensive']
【问题讨论】:
-
使用列表理解:
a = [s[2:] for s in a] # ['llo', 'ings', 'coming', 'pensive']