Addition and multiplication of strings
Strings can be added, for this the sign "
+
" is used. This operation is called string concatenation or
concatenation.
Example
s = "Hello,"
s1 = "world"
print(s + s1)
The screen will display the phrase "
Hello world
" (without quotes).
Python implements the operation of multiplying a string by a number: it replaces multiple addition.
Example
string
s = "world "+"world "+"world "+"world "
can be replaced by
s = "world " *4