Python中我们经常会用到join函数。
join函数的基本格式是:
''.join()
引号中加上你想要用来隔开字符的符号(可以是数字,字母,空格等其他符号),括号中加上一个可迭代对象。
字符串
str = 'hello world'
print(' '.join(str))
h e l l o w o r l d
列表
list = ['hello','world']
print(' '.join(list))
hello world
元组
tuple = ('hello world')
print(' '.join(tuple))
h e l l o w o r l d
字典
dict = {'action':'hello','name':'world'}
print(' '.join(dict))
action name
集合
set = {'1','2','3'}
print(' '.join(set))
2 1 3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)