AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

Python String Concatenation Best Practice-Trickcode

By pushpam abhishek
Listen to this article
Python String


Python String Concatenation

String concatenation is likely something you will need sooner or later. Python offers several possibilities to fulfill this task. Here we will present two of the most common methods. The first method is using +-operator. The following snippet provides an example:
Here the two strings are combined into a new string, using the +-operator. Similar to what you might find in other languages.

The second popular method uses lists and “join”, as shown in the following example:
Here the strings in the list are >joined< with the string/character the join function was called on. This method is very similar to using string buffers in other languages.

Both methods are fine to use, but many Python programmers prefer the first method over the second because it seems more readable. Functionally there is no difference and from a performance standpoint there usually is little difference between the two in practice. However, when performance is critical, it is always sensible to benchmark the two methods and then make a decision.

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments