" "python string connection operation" "#Method 1 via + connectionA, B ='Hello','Hadoop'Print(A +b)#Method 2 through, connectPrint(A, b)#assignment operation will narimoto group#Method 3 Direct connection, there are no spaces canPrint('Hadoop' 'Hive')Print('Hadoop"'Hive')#Method 4 using the% operatorPrint('%s%s'% ('Hello',' World'))Print('%s%s'% ('Hadoop','Java'))#Format between% determines the format of the output resultPrint('%s\n%s'% ('Hadoop','Java'))Print('%s\t%s'% ('Hadoop','Java'))#Method 5 Format MethodsPrint('{}{}'. Format ('Hello',' World'))Print('{}\t{}'. Format ('Hello',' World'))#Format between {} determines the format of the output resultPrint('{}\n{}'. Format ('Hello',' World'))" "Method 6 The join string has a built-in methods join whose arguments are a sequence type, such as an array or a tuple. " "Print('='. Join (['a','b','DD']))#The output format determines for itself#Method 7 Using the F-string method" "' Python 3.6 introduces the formatted string literals (literal formatting string), abbreviated f-string,f-string is the evolution version of the% operator and the format method, using the F-string connection string method Similar to using the% operator, format method. " "Print(f'{a}{b}')Print(f'{A} {B}')#The output format determines for itselfPrint(f'{a}+{b}')Print(f'{a}-{b}')Print(f'{a}=>{b}')#Method 7 * operator ConnectionPrint(a*3)#* operator is actually an operator overloaded operation, the corresponding Magic method is __mul__" "Summary: When connecting a small number of strings, it is recommended to use the + sign operator. If you have high performance requirements, and the Python version is above 3.6, we recommend using F-string. For example, the following f-string readability is much better than the + sign:" "name='Hadoop' Age= 12Gender='Femal'a= f'name: {name} Age: {ages} Gender: {gender}'b='Name:'+ name +'\ t Age:'+ STR (age) +'\ t Sex:'+GenderPrint(a)Print(b)" "Joins and f-string are recommended when connecting a large number of strings, and depending on the version of Python you use and the readability requirements you choose. " "
Python String Connection Operation summary