2022
我们一起努力

python中有哪些拼接字符串的方法

python中拼接字符串的方法有:1.直接连接;2.使用加号连接;3.使用逗号连接;4.使用%连接;5.使用format连接;6.使用f-string方式连接;7.使用join方法连接;

python中有哪些拼接字符串的方法

python中拼接字符串的方法有以下几种

1.直接连接字符串

print(\'heelo\' \'world\')

print(\'heelo\'\'world\')

2.使用加号连接字符串

>>> a,b = \'heelo\',\'world\'

>>> a + b

\'heelo world\'

3.使用逗号连接字符串

>>> a,b = \'heelo\',\'world\'

print(a,b)

>>> heelo world

4.使用%连接字符串

print(\'%s %s\' % (\'heelo\',\'world\'))

5.使用format连接字符串

print(\'{} {}\' .format (\'heelo\',\'world\'))

6.使用f-string方式连接字符串

>>> aa, bb = \'heelo\',\'world\'

>>> f\'{aa}{bb}\'

\'heelo world\'

7.使用join方法连接字符串

print(\'-\'.join([\'aa\',\'bb\',\'cc\']))

赞(0)
文章名称:《python中有哪些拼接字符串的方法》
文章链接:https://www.fzvps.com/64441.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!