HTuse
Python ·
10 steps
How to Concatenate Strings in Python?
Use the `+` operator: `s3 = s1 + s2`
Use `+=` for appending: `s1 += s2`
Use `join()` for multiple strings: `''.join([s1, s2, s3])`
Use f-strings: `f"{s1}{s2}"`
Use `format()`: `"{}{}".format(s1, s2)`
Use `%` formatting: `"%s%s" % (s1, s2)`
Use `join()` with a separator: `' '.join(words)`
Use `str.join()` on an iterable: `separator.join(iterable)`
Use `map(str, items)` before joining non-strings: `''.join(map(str, items))`
Use `pathlib` or `os.path.join()` for file paths, not string `+` concatenation