Several methods of Python string concatenation __python

Source: Internet
Author: User
Tags python string concatenation
several ways to stitch python strings:

1, str1 + str2

I think most people will use the + number for string stitching; eg: ' WBZ ' + ' ctt ' = ' wbzctt '

2, STR1,STR2

This is a bit special, if two strings are separated by commas, then the two strings will be Mulao, but there will be spaces in the middle of the new string after stitching; eg: ' WBZ ', ' ctt ' = ' WBZ CTT '

3, str1 str2

This mosaic is unique to Python, as long as the two strings together, the two strings will be automatically spliced into a new string, regardless of whether there is a space between the two strings; eg: ' WBZ ' ctt ' = ' wbzctt ' WBZ ' CTT ' ' WBZCTT '

4,% connection string

This is a bit more powerful than the other stitching methods, as it draws on the functions of the printf () function in the C language. This way the symbol '% ' joins a string and a set of variables, and special tags in the string are automatically replaced with the variables in the right variable group; eg: '%s '% (' WBZ ', ' ctt ') = ' WBZ CTT '

5, the String list connection Str.join (list)

This function join accepts a list and burns each element in the list by using a string;

data = [' WBZ ', ' CTT ', ' Python ']
str = ' @@@ '
str.join (data) = ' wbz@@ zzfcthotfixz @@ zzfcthotfixz '
6. String multiplication This method is also possible to string concatenation, but this way is not often used;
str = ' Python '
str * 2 = ' Pythonpython '
Here is the end of sharing ~ ~ ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.