Can we concatenate multiple strings at once?


#1

Question

In Python, can we concatenate multiple strings at once, as in, in a single statement?

Answer

String concatenation is not limited to only adding two strings per statement. In a single statement, you can concatenate multiple strings at once.

When concatenating many strings, however, you may have to consider that spaces are not added automatically.

Example

string1 = "Strings "
string2 = "are "
string3 = "fun"
string4 = "!"

# Concatenating multiple strings
string1 += string2 + string3 + string4

print(string1) # Strings are fun!