There are many string Connection Methods in python. I am writing code today. By the way, from the original string connection method to the string list connection, we can see that python has many string connection methods, I am writing code today. By the way, I would like to summarize:
The most primitive string connection method: str1 + str2
New python string connection Syntax: str1, str2
Strange string method: str1 str2
% Connection string: 'name: % s; sex: '% ('Tom', 'male ')
String list connection: str. join (some_list)
First, as long as you have programming experience, we all know that you can directly use "+" 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 the strings:
'Jim ', 'green' = 'Jim green'
The third type is exclusive to python. As long as the two strings are put together, there is blank or no blank in the middle: The two strings are automatically connected to one string:
'Jim ''green' = 'jimgreen'
'Jim ''green' = 'jimgreen'
The fourth feature is quite powerful. I have used the printf function in C language for reference. If you have the C language basics, read 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 type is a skill. 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'
In fact, there is also a string connection method in python, but not many are used, that is, string multiplication, such:
A = 'abc'
A * 3 = 'abcabcabc'