python字符串转数组,数组转字符串方法
# 字符串转数组 split 不带参数 str = "a,b,c" str = str.split(",") print(str) #['a','b','c']
# split 第二个参数 用法从左边起第几个有效 str = "a,b,c,d" str1 = str.split(",",1) str2 = str.split(",",1) print(str1) #['a','b,c,d'] print(str2) #['a','b','c,d']
# rsplit 第二个参数 用法从右边起第几个有效 str = "a,b,c,d" str1 = str.rsplit(",",1) str2 = str.rsplit(",",1) print(str1) #['a,b,c','d'] print(str2) #['a,b','c','d']
------------------------------
# 数组转字符串 arr = ['a','b','c','d'] str1 = ','.join(arr) print(str1) # a,b,c,d