Python Concat String

Aug 9, 2017
Format string, join list or append string.

Format String

If you want to join a fixed number of variables in a fixed format, string.format is your best bet.

value = u"Desmond Lua 赖忠景"field = "Name"# use 'u' to properly handle unicode formatting output = u"{0}: {1}".format(field, value)

You can also use + operator to concat string.

output = field + ": " + value

Join list

If you have an array of strings which you would like to join together, string.join is convinient and fast.

values = ["Please", "join", "these", "words", "together"]output = " ".join(values)

Manually append string

If you want to manually append string without using a list, you can use += operator.

output = "Please"output += "Join"output += "Us"output += "Together"

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.