To append a string to another string in Python, you can use the +
operator or string formatting.
In this example,
str1
with a value of "Hello"
.+
operator to append the string " World"
to str1
.+
operator concatenates the two strings and returns the result.str1 = "Hello"
concatenated = str1 + " World"
print(concatenated)
Hello World
In this example,
str2
with a value of "banana"
."apple"
to str2
.str2 = "banana"
concatenated = "%s%s" % (str2, "apple")
print(concatenated)
bananaapple
In this tutorial, we learned How to Append a String to another String in Python language with well detailed examples.