网络编程
位置:首页>> 网络编程>> Python编程>> Python字符串拼接的几种方法整理

Python字符串拼接的几种方法整理

作者:Godliness丶  发布时间:2021-05-08 18:55:47 

标签:Python,字符串

Python字符串拼接的几种方法整理

第一种 通过加号(+)的形式


print('第一种方式通过加号形式连接 :' + 'love'+'Python' + '\n')

第二种 通过逗号(,)的形式


print('第二种方式通过逗号形式连接 :' + 'love', 'Python' + '\n')

第三种 直接连接 中间有无空格均可


print('第三种方式通过直接连接形式连接 (一) :' + 'love''Python' + '\n')
print('第三种方式通过直接连接形式连接 (二) :' + 'love'  'Python' + '\n')

第四种 格式化


print('第四种方式通过格式化形式连接 :' + '%s %s' % ('love', 'Python') + '\n')

第五种 join方式连接


str_list = ['love', 'Python']
print('第五种方式通过join形式连接 :' + ''.join(str_list) + '\n')

运行结果

Python字符串拼接的几种方法整理

来源:http://blog.csdn.net/qq_878799579/article/details/74279842

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com