python字符串与列表的相互转换

短命女 2022-01-15 04:25 485阅读 0赞

学习内容:

1.字符串转列表

2.列表转字符串

1. 字符串转列表

  1. str1 = "hi hello world"
  2. print(str1.split(" "))
  3. 输出:
  4. ['hi', 'hello', 'world']

2. 列表转字符串

  1. l = ["hi","hello","world"]
  2. print(" ".join(l))
  3. 输出:
  4. hi hello world

发表评论

表情:
评论列表 (有 0 条评论,485人围观)

还没有评论,来说两句吧...

相关阅读