1, directly through the + operation:
' Python ' + ', ' +' hello ' + '! ‘
Print (s)
Printing results:
Python, Hello!
2. Splicing by Join () method:
Convert a list to a string
strlist=[' Python ', 'hello '! ‘]
Print (". Join (strlist)")
Printing results:
Python, Hello!
3, through the format () method splicing:
The number of {} in the string is consistent with the number of parameters in the format () method
‘{},{}! '. Format (' Python 'hello ')
Print (s)
Printing results:
Python, Hello!
4, through the% splicing:
'%s,%s! '% (' Python 'hello ')
Print (s)
Printing results:
Python, Hello!
5, through () Multi-line splicing:
When Python encounters an unclosed parenthesis, it automatically stitches multiple lines into a row
s = (
' Python '
‘,‘
Hello
‘! ‘
)
Print (s)
Printing results:
Python, Hello!
6. Splicing through the template object in the string module:
Import Template
s = Template (' ${s1},${s2}! ‘)
# template is implemented by first initializing a string through the template
# These strings contain a key
Print (S.safe_substitute (s1=' Python 's2=' Hello '))
# by calling substitute or Safe_subsititute
# The key value corresponds to the parameter passed in the method.
# to implement importing strings at the specified location
Printing results:
Python, Hello!
7, by F-strings (string interpolation) splicing:
' Python '
Hello
Print (f ' {s1},{s2}! ‘)
Printing results:
Python, Hello!
7 Ways to stitch a python string