str.join(): 将字符插入对象中间返回一个长字符串
In [1]: print(' and '.join(['Mary']))
print(' and '.join(['Mary','John']))
print(' and '.join(['Mary','John','Amy']))
Out [1]: Mary
Mary and John
Mary and John and Amy
str.format(): 替换字符中间的'{}'
In [2]: print(' 你和{}'.format('我'))
print(' 你和{}和{}'.format('我','他'))
Out[2]: 你和我
你和我和他
本文介绍了Python中使用str.join()和str.format()进行字符串拼接和格式化的技巧,通过实例展示了如何利用这些方法高效处理字符串数据。

580

被折叠的 条评论
为什么被折叠?



