array Python module
| ast Python module
| code Python module
| COM PHP module
| dis Python module
| Ev PHP module
| imp Python module
| io Python module
| operator Python module
| os Python module
| PS PHP module
| Python functions
| re Python module
| resource Python module
| SPL PHP module
| string Python module
| Strings PHP module
| UI PHP module
👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
Concatenation is a technique used in programming to join two or more strings into a single value. For example, you might have two employee lists stored as strings, one for each branch of your business. You can merge them all into a list of all your employees.
There are two ways to concatenate a string:
- Using the concatenation operator (+).
- Using the concat () method.
The concat () method supports the browser on all modern browsers.
There is a method called Array.concat () which concatenates two arrays. In this article, we’ll focus on the string concat () method.
Here is the syntax of the concatenation operator:
Concatenation is useful if you have separate string values ‚Äã‚Äãthat you want to display as one. For example, suppose we have two strings. A string contains the name of a user. The other string contains the last name. You can combine these two values ‚Äã‚Äãto get the entire name as a string.
Suppose that we wanted to join two strings. One string is the name of a customer. Another string is the last name of that customer. We join these two strings using the "+" operator:
Our code returns: " BillJohnson ". Our strings are not automatically separated by a space. If we want a space between our strings, we need to specify one in one of our strings:
Our code returns now: "Bill Johnson.‚" That’s because we’ve added a space in the "Bill‚" string.
You can pass as many parameters as you want in concat ().
Let’s take an example to illustrate how the concat () string function works in action. Let’s say we have a user’s first, middle and middle names and want to combine them into one string. We could use the following code to achieve this:
Our code returns: "Lucy Turnbull Cooper". It is important to note that we have included spaces at the beginning of "second_name & rdquo; and " second_name ". This ensures that our final string has been separated by spaces.
You can also use the concat () function to combine more than two strings. Here is an example of concat () used to combine three strings:
Our code returns a new string: " Hello, Alex ! It’s a great day!"
Our code returns the same as above, but now our new string is stored in the variable "new_string."
These two methods can be used interchangeably. This means that none of them offer special methods. The plus sign and the concat () method join the strings to create a new string.
👻 Read also: what is the best laptop for engineering students?
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
Paris | 2023-03-26
Texas | 2023-03-26
Milan | 2023-03-26