python列表连接_Python连接列表

python列表连接

Python join list means concatenating a list of strings with a specified delimiter to form a string. Sometimes it’s useful when you have to convert list to string. For example, convert a list of alphabets to a comma-separated string to save in a file.

Python连接列表意味着将字符串列表与指定的分隔符连接起来以形成字符串。 有时在必须将列表转换为字符串时很有用。 例如,将字母列表转换为逗号分隔的字符串以保存在文件中。

Python连接列表 (Python Join List)

We can use python string join() function to join a list of strings. This function takes iterable as argument and List is an interable, so we can use it with List.

我们可以使用python string join()函数来连接字符串列表。 该函数将iterable作为参数,并且List是一个可互操作的,因此我们可以将其与List一起使用。

Also, the list should contain strings, if you will try to join a list of ints then you will get an error message as TypeError: sequence item 0: expected str instance, int found.

另外,该列表应包含字符串,如果您尝试加入一个ints列表,则将收到错误消息,类型错误TypeError: sequence item 0: expected str instance, int found

Let’s look at a short example for joining list in python to create a string.

让我们看一个简短的示例,在python中加入list来创建一个字符串。

vowels = ["a", "e", "i", "o", "u"]

vowelsCSV = ",".join(vowels)

print("Vowels are = 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值