on将列表或元组中的每个元素连接起来,举个例子:
1 a = ["hello", "world", "dlrb"] 2 a1 = "_".join(a) 3 print(a1)
输出结果:
hello_world_dlrb
"_".join(a) 的作用:使用 _ 下划线将列表a中的每一个元素连接起来,当然你可以选择自己想要用的连接方法
1 b = ("hello", "world", "dlrb") 2 b1 = "*".join(a) 3 print(b1)
输出结果:
hello*world*dlrb
和列表同理