jtxs0000 发表于 2020-7-28 15:39:02

python的字符串与列表拼接要怎么弄

a = ("python")
b = ["good","nice","great"]


如何让结果变成:
["pythongood",["pythonnice"],"pythongreat"]

jtxs0000 发表于 2020-7-28 15:40:05

["pythongood","pythonnice","pythongreat"]

这样的,中间的那个 []多打了

Twilight6 发表于 2020-7-28 15:40:31

本帖最后由 Twilight6 于 2020-7-28 15:42 编辑


for 循环和 a 字符串拼接就好,如果想在原列表上进行改变就这样:

a = ("python")    # 实际上这里 相当于a = "python"
b = ["good","nice","great"]
for i in range(len(b)):
    b = a+b

print(b)

重新创建个列表就这样,用列表推导式了:
a = ("python")
b = ["good","nice","great"]
new =

print(new)

1q23w31 发表于 2020-7-28 15:42:11

a = ("python")
b = ["good","nice","great"]
s = for j in range(len(b))]
print(s)
页: [1]
查看完整版本: python的字符串与列表拼接要怎么弄