Home  >  Article  >  Backend Development  >  Summary of Python string concatenation methods

Summary of Python string concatenation methods

巴扎黑
巴扎黑Original
2017-08-06 17:10:531677browse

This article mainly introduces the relevant information compiled by several methods of Python string splicing. Five methods and implementations are provided here. Friends in need can refer to the following

Python string splicing Several ways to organize

The first is in the form of a plus sign (+)


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

The second form is through comma (,)


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

The third type of direct connection can be done with or without spaces


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

The fourth format


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

The fifth join method connection


##

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

Running result

The above is the detailed content of Summary of Python string concatenation methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn