栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python字符串连接 join

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python字符串连接 join

字符串连接 join

my_str.join(可迭代对象)
可迭代对象, str,列表(需要列表中的每一个数据都是字符串类型)
将my_str这个字符串添加到可迭代对象的两个元素之间
返回值:一个新的字符串,不会改变原字符串的值

str1 = 'hello world IT Python and Pythonxcc'
str1 = '_'.join('hello')  # 会把_加入到 hello每两个元素之间即 h_e_l_l_o
print(str1)
print('_*_'.join('he1lo'))  # h_*_e_*_L_*_L_*_o
# 定义列表
list1 = ['hello', 'cpp', 'python']
print("_".join(list1))
print("_*_".join(list1))
print( " ".join(list1))

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/977537.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号