Summary of Python string concatenation methods

巴扎黑
Release: 2017-08-06 17:10:53
Original
1685 people have browsed it

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')
Copy after login

The second form is through comma (,)


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

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


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

The fourth format


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

The fifth join method connection


##

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template