String Concatenation
When we use the + operator with the numbers, we are just performing the addition. For example, 5 + 6 is 11. But what if we are using the same + operator with the strings? Well, this would be something called string concatenation. This simply means that we are joining the two strings. If we are doing ‘Hello’ + ‘GyaniPandit’, it would be ‘HelloGyaniPandit’. Let’s have a look at a program, which demonstrates string concatenation.
Python String Concatenation
As you can see, we have two strings in the program, and in the later instruction, we are concatenating them. As stated earlier, concatenation means joining the two strings. If you try to run the above program, you will simply see the two strings being concatenated, which simply means that the output should be simply ‘HelloGyaniPandit’.
You can assign that concatenated string to some variable if in case we are required to use the value later in the program. Have a look at the below program, which explains the same thing.
As you can see, the concatenated string is being assigned to another variable, and in case we are required to use that concatenated string later in the program, we can simply use it. If you run the above program, there would be no change in the output, but we have assigned that concatenated string to another variable. You can further try concatenating more strings and observe the outputs accordingly. Also, we would perform string concatenation as and when needed.