Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Python strings are concatenated

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to concatenate Python strings, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Plus sign

If you have experience in developing other programming languages, you must know that in many languages, two strings are concatenated with a plus sign. In Python programming language, two strings can also be concatenated directly with "+".

Print 'Python' +' Tab'

Results:

PythonTab

Comma

Concatenate two strings with a comma. If two strings are separated by a comma, the two strings will be concatenated, but there will be an extra space between the strings.

Print 'Python','Tab'

Results:

Python Tab

Direct connection

This method is unique to Python. As long as you put two strings together with or without white space, the two strings will be automatically concatenated into one string.

Print 'Python''Tab'

Results:

PythonTab

Formatting

This way is more powerful, drawing lessons from the function of the printf function in C language, if you have a C language foundation, take a look at the document to know. In this way, a string and a set of variables are concatenated with the symbol "%", and the special token in the string is automatically replaced with the variable in the variable group on the right:

Print's% slots% ('Python',' Tab')

Results:

Python Tab

Join () function

It's a trick, using the function join of the string. This function takes a list and concatenates each element of the list with a string in turn:

Str_list = ['Python',' Tab']

A =''

Print a.join (str_list)

Results:

PythonTab

Thank you for reading this article carefully. I hope the article "how to concatenate Python strings" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report