使用列表理解尝试此方法 -n = 5s = 'z'out = [None if i!=n-1 else s for i in range(n)]print(out)[None, None, None, None, 'z']如果你想在中间某处插入字符串,那么更通用的方法是分别定义 m 和 n,其中 n 是列表的长度,m 是位置 -n = 5m = 3s = 'z'out = [None if i!=m-1 else s for i in range(n)]print(out)[None, None, 'z', None, None]