String Concatenation is the technique of combining two strings. It can be done using many ways. If we put string literals next to each other (with or without spaces), they will be joined into one string. This is called concatenation:
Example:
>>> "Hello " "kids." 'Hello kids.' >>> "Hello ""kids." 'Hello kids.'
We use the multiplication operator * with strings to repeat them, when a string is multiplied with an integer n, the string is repeated n times. The * operator is known as the string repetition operator.
Example:
>>> "It's s" + "o" * 10 + " good!" "It's soooooooooo good!" >>> 'ha ' * 20 'ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ' >>> question = "Were you shocked?" >>> answer = question[10:12] + " " >>> answer * 5 'ho ho ho ho ho '
We can also use the augmented assignment operator *=
So, *a = b is the same as a = a * b
>>> pattern1 = "-oo-" >>> pattern1 = pattern1 * 3 >>> pattern1 '-oo--oo--oo-' >>> pattern2 = "=XX=" >>> pattern2 *= 3 >>> pattern2 '=XX==XX==XX='