Python,创建一个字符串,元素之间添加逗号
Python, Make one string with elements adding comas between them
我想在元素之间用逗号创建一个字符串,如下所示:
在:
['ElementA','ElementB','ElementC']
输出:
['ElementA,ElementB,ElementC']
谢谢
Javascript解决方法:
let arr = ['ElementA','ElementB','ElementC'] ;
let arr2 = [arr.join(",")];
console.log(arr2);
Python解法:
arr = ['ElementA','ElementB','ElementC']
separator = ','
arr2 = [separator.join(arr)]
print(arr2)
我想在元素之间用逗号创建一个字符串,如下所示:
在:
['ElementA','ElementB','ElementC']
输出:
['ElementA,ElementB,ElementC']
谢谢
Javascript解决方法:
let arr = ['ElementA','ElementB','ElementC'] ;
let arr2 = [arr.join(",")];
console.log(arr2);
Python解法:
arr = ['ElementA','ElementB','ElementC']
separator = ','
arr2 = [separator.join(arr)]
print(arr2)