Search code examples
pythonconcatenation

How does the `join` operator work for string concatenation?


How can I properly use this operator to concatenate two strings?

string = "Hello"

a = " ".join(string, "World")

print(a)

Output ~ TypeError: join() takes exactly one argument (2 given)


Solution

  • The argument to join is basically an iterable, so you just need to put your strings as a list

    You can do something like:

    " ".join([string," World"])