踩了个join的坑,刚开始以为就是个简单的把两个字符串拼接起来的函数,并不是!
先放官方说明
str. join(iterable) : iterable可以是列表、元组、字符串。str 作为拼接时的分割符号,可以为空
列表:
list = ['tom','is','a','student']
s = ' '.join(list)
print(s)
output:tom is a student
元组
tuple = ('tom','is','a','student')
s = ' '.join(tuple)
z = ''.join(tuple)
print(s)
print(z)
output1:tom is a student
output2:tomisastudent
字符串
cc = 'tomisastudent'
s = ' '.join(cc)
print(s)
output:t o m i s a s t u d e n t