N methods of python string connection

Source: Internet
Author: User

There are many string Connection Methods in python. To sum up:
1 original string connection method: str1 + str22 new python string connection Syntax: str1, str23 strange string method: str1 str24 % connection string: 'name: % s; sex: '% ('Tom', 'male') 5 string list connection: str. join (some_list) First, presumably as long as there is a programming experience, it is estimated that we all know that directly using "+" to connect two strings:
'Jim '+ 'green' = 'jimgreen' the second type is special. If the two strings are separated by commas, the two strings will be connected. However, there will be an extra space between strings:
'Jim ', 'green' = 'Jim green' the third type is unique to python. If you put the two strings together, there is a blank or no blank in the middle: the two strings are automatically connected to one string:
'Jim ''green' = 'jimgreen'' 'Jim ''green' = 'jimgreen' the fourth function is quite powerful. It draws on the printf function in C language, if you have the C language basics, you can see the documentation. In this way, use the symbol "%" to connect a string and a group of variables. The special mark in the string will be automatically replaced with the variable in the variable group on the Right:
'% S, % s' % ('Jim', 'green') = 'Jim, green' the fifth is a technique. Use the string function join. This function accepts a list and uses strings to connect each element in the list in sequence:
Var_list = ['Tom ', 'David', 'john']
A = '### 'a. join (var_list) = 'Tom ### david ### john'

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.