Python Glossary Русский

all Python 3Strings (str)term

+ string concatenation

operators

The + operator joins two strings into a new one. Both operands must be strings.

Syntax

s1 + s2

Both operands must be strings: 'year ' + 2026 raises TypeError, so wrap the number in str() or use an f-string instead. Every + builds a brand-new object, so concatenating inside a loop recopies the whole accumulated string each time — collect the pieces in a list and hand them to ''.join() when there are many.

Examples

print('Hello' + ' ' + 'World')
# → 'Hello World'
a = 'foo'
b = 'bar'
print(a + b)
# → 'foobar'
print('py' + 'thon')
# → 'python'
prefix = 'pre_'
print(prefix + 'fix')
# → 'pre_fix'
print('' + 'empty left')
# → 'empty left'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy