python拼接字符串的方法有哪些?
发布时间:2024-10-09 14:35:53
3. templatet使用templatet
>>>fromstringimportTemplate
>>>t=Template('Hello,$a!')
>>>t.substitute(a='world')
'Hello,world!'4.直接连接中间是否有空间
print('hello''world')
print('hello''world')5.使用%操作符
在 Python 2.6 以前,% 操作符是连接字符串的唯一格式化方法。
print('%s%s'%('hello','world'))今天python拼接字符串方法的扩展到此结束。有时候我们可以选择不常用的拼接字符串方法,可能会有意想不到的惊喜。
