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 =