【问题标题】:How do you turn lists with multiple characters into strings? [duplicate]如何将包含多个字符的列表转换为字符串? [复制]
【发布时间】:2015-04-16 04:48:37
【问题描述】:

我对编程很陌生,并且看过许多类似问题的答案,但它们并没有产生我想要的结果。你们中的任何人都可以帮助我吗? 示例代码:

shapes = ["tri", "angle"]

groupedShapes = "triangle"

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    根据doc's

    string.join(words[, sep]) 将单词列表或元组与中间出现的 sep 连接起来。 sep 的默认值是一个空格字符。

    shapes = ["tri", "angle"]
    groupedShapes = "".join(shapes)
    # "triangle"
    

    【讨论】:

      猜你喜欢
      • 2012-10-21
      • 2012-05-23
      • 2012-02-02
      • 2012-10-11
      • 2015-08-01
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      相关资源
      最近更新 更多