python

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

关关
171
2021-05-14 15:41:15
栏目: 编程语言

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
看了该问题的人还看了