Concatenation

Concatenation is the process of combining multiple string (text) messages into one. For example if you have a variable with value “Hello ” and another variable with value “How are you?”. You can combine those two variables using concatenation. In Python concatenation is performed using the plus + sign

Example of Python concatenation:

In the above example, we are concatenating (combining) two variables (message1 and message2) string type values into one variable (finalMessage). Finally we are using print function to show the value of finalMessage.

Concatenation works great for text type data (strings), however if we try to combine a string with integer (number) type data then it would not work. The below code will produce an error.

The reason the above code will produce an error is because using the concatenation operator (+) we can not combine an integer (23) with a string (John). To achieve that we will use string interpolation.