1. python-内建函数-拼接函数join
-
join()函数: 将序号中的元素以指定的字符串连接,生成一个新的字符串。
-
示例:
-
示例1:拼接字符串
s = "lizhenliang" r = '.'.join(s) print(r)
-
示例2:拼接序列
computer = ["主机","显示器","鼠标","键盘"] r = ','.join(computer) print(r)
-
2. 拼接函数案例
-
拼接函数案例
#!/usr/bin/env python3 # _*_ coding: utf-8 _*_ # Author:shichao # File: .py # 原有拼接使用"+" s = "zhangsan" for i in s: print(i + ".",end="") # 默认是要换行的加了/n,我们传一个end进去,不换行 print("\n ----") # 使用内建函数,拼接函数join a = "zhangsan" r = '.'.join(a) print(r) # 序列 computer = ["主机","显示器","鼠标","键盘"] r = ','.join(computer) print(r)