When one codes computer tools and software in their favorite computer programming language, they deal with a lot of frustration, especially in the beginning when they don’t know what they’re really doing. Based on my personal experience with the Python computer programming language, there are many different ways to accomplish a certain task with Python, but only a few of them are accepted as legit and the norm by those who get paid to write professional code.
Not that there is completely wrong to accomplish your tasks in Python computer programming language by going your own way, but it is always a good idea to stay updated with the latest tips from the professional software developers as they get paid to solve coding problems, and they know for sure what they do.
Right now, I am writing a project in Python computer programming language and there is a problem which has occurred to me. From my personal experience with the Python computer programming language, I believe I do know two ways to solve my problem from a coding perspective.
What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.
So what is the problem that has occurred to me and that needs to be solved? I need to join two strings separated by a dot like shown below.
test # first string
mp4 # second string
test.mp4 # final stringRecommended for you: Get network issues from WhatsUp Gold. Not end users.
According to a book which I am studying, related to the Python computer programming language, one can easily perform string concatenation by using the addition arithmetic operation like shown in the following example.
‘test’ + ‘.’ + ‘mp4’
Although the above technique works when it comes to joining strings together in Python computer programming language, the professional software developers recommend another method to accomplish the same task. According to the official Python documentation, string objects support a specific method called join, which takes a list of strings and joins them together.
One can easily use the string specific method called join like shown below.
‘,’.join([‘a’, ‘b’])
When the above piece of Python code is been executed in the interactive console, the following output is being displayed.
‘a,b’
Based on the above technique, one can easily concatenate two strings together separated by a dot like shown in the following example. The syntax is very clear and easy for anyone to understand.
‘.’.join([‘test’, ‘mp4’])
Once the above Python operation is executed on my interactive console, the following comes up.
‘test.mp4’
As you can see from the above output, one can make use of the specific string method called join, to concatenate together a list of things.
Final thoughts
As I mentioned earlier in this article, one can accomplish a certain task in many different ways when it comes to the Python computer programming language, but there are only a few ways accepted and used by the professionals. The .join method is perfect when one needs to join strings together, especially separated by a dot.