append a string to the end of another string in python

main.py
string1 = "Hello "
string2 = "World!"
string1 += string2
print(string1)
72 chars
5 lines

Output:

main.py
Hello World!
13 chars
2 lines

In python, we can concatenate two strings using the + operator. Here, we first define two strings string1 and string2. Then, we use the += operator to add string2 to the end of string1. Finally, we print string1 which now contains both the strings concatenated together.

related categories

gistlibby LogSnag