Python

More on Strings

Additional information regarding the advanced properties of strings

Concatenation

Another thing we should cover before getting to the logic part of programming is concatenation. Concatenation is an intuitive way to combine strings. All you have to do is put a ‘+’ between strings to combine them. It is especially useful in making results understandable.

num1 = 6
num2 = 15
sum = num1 + num2
print(“The sum is ” + sum)

Output:

The sum is 21

Do note that the ‘sum’ variable is storing an integer value. Luckily, Python is intelligent and realizes that when we are joining a string to the sum value, we want to treat it as a string(text) and not as a number to add to the text. Thus, the output is as we want it.

chevron_up