1. Connect ' AA ' BB between strings
Can be a space or nothing at the center.
Then the output is closely connected to each other.
2. String + number
' AA ' +90
This will cause an error, because different types cannot be added,
can be used ' AA ', 90. This is possible, but there is a space in the middle.
3,% placeholder
print '%s,%s '% (' Tom ', ' Jerry ')
[Python]View PlainCopy
- >>> Print ' aaa ',
- AAA
- >>> print ' AA '
- Syntaxerror:invalid syntax
- >>> print ' AA ' +
- Traceback (most recent):
- File "<pyshell#5>", line 1, in <module>
- print ' AA ' +
- Typeerror:cannot concatenate ' str ' and ' int ' objects
- >>> print ' AA ' +' CAA '
- Aacaa
- >>> print ' aa ' bb '
- Aabb
- >>> print ' AA 'rr '
- Aarr
- >>> print ' AA ',
- AA
- >>> print '%s,%s '% (' Tom ',' Jerry ')
- Tom,jerry
- >>> '%s,%d '% (' Tom ', ' a ')
- ' Tom,56 '
- >>>
Three ways to concatenate strings in Python