1. 程式人生 > >python中join()函式講解

python中join()函式講解

本文簡述的是string.join(words[, sep]),它的功能是把字串或者列表,元組等的元素給連線起來,返回一個字串,和split()函式與正好相反,看下面的程式碼理解。

a=["豫","N","C8","C89"]
b=("豫","N","C8","C89")
c="zhang"

a1="-".join(a)

b1="-".join(b)

c1="-".join(c)

d="".join(a)

print(a1)
print(b1)
print(c1)
print(d)

輸出:
豫-N-C8-C89
豫-N-C8-C89
z-h-a-n-g
豫NC8C89