OneBite.Dev - Coding blog in a bite size

combine two strings in python

Code snippet on how to combine two strings in python

str1 = "Hello" 
str2 = "World"
str3 = str1 + str2
print(str3)

This code will combine the two strings, “Hello” and “World”. First, two variables, str1 and str2, are declared, and each contain one of the strings. str1 is assigned “Hello” and str2 is assigned “World”. The third variable, str3, is then declared; this variable combines the two strings assigned to str1 and str2 by using the + operator. The two strings are combined, and the new combined string is assigned to str3. Finally, the code prints the new combined string which has been assigned to str3. So, when the code has been run, the output should be “HelloWorld”.

python