Skip to content

Instantly share code, notes, and snippets.

@tinjaw
Created January 24, 2020 18:07
Show Gist options
  • Save tinjaw/9e0ecee978d1a42c1c0d0d4e2c1a99b7 to your computer and use it in GitHub Desktop.
Save tinjaw/9e0ecee978d1a42c1c0d0d4e2c1a99b7 to your computer and use it in GitHub Desktop.
When you need to concatenate a list of strings, you can do this using a for loop by adding each element one by one. However, this would be very inefficient, especially if the list is long. In Python, strings are immutable, and thus the left and right strings would have to be copied into the new string for every pair of concatenation.
A better approach is to use the join() function as shown below:
```python
characters = ['p', 'y', 't', 'h', 'o', 'n']
word = "".join(characters)
print(word) # python
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment