
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Add one Python string to another
By adding strings in python we just concatenate them to get a new string. This is useful in many scenarios like text analytics etc. Below are the two approaches we consider for this task.
Using += Operator
The + operator can be used for strings in a similar was as it is for numbers. The only difference being, in case of strings the concatenation happens and not a numeric addition.
Example
s1 = "What a beautiful " s2 = "flower " print("Given string s1 : " + str(s1)) print("Given string s2 : " + str(s2)) #Using += operator res1 = s1+s2 print("result after adding one string to another is : ", res1) # Treating numbers as strings s3 = '54' s4 = '02' print("Given string s1 : " + str(s3)) print("Given string s2 : " + str(s4)) res2 = s3+s4 print("result after adding one string to another is : ", res2)
Output
Running the above code gives us the following result −
Given string s1 : What a beautiful Given string s2 : flower result after adding one string to another is : What a beautiful flower Given string s1 : 54 Given string s2 : 02 result after adding one string to another is : 5402
Using join
We can use the join() in a similar manner as the plus operator above. We can join any number of strings using this method. The result will be same as the plus operator.
Example
s1 = "What a beautiful " s2 = "flower " print("Given string s1 : " + str(s1)) print("Given string s2 : " + str(s2)) print("result after adding one string to another is : "," ".join((s1,s2))) # Treating numbers as strings s3 = '54' s4 = '02' print("Given string s1 : " + str(s3)) print("Given string s2 : " + str(s4)) print("result after adding one string to another is : ","".join((s3,s4)))
Output
Running the above code gives us the following result −
Given string s1 : What a beautiful Given string s2 : flower result after adding one string to another is : What a beautiful flower Given string s1 : 54 Given string s2 : 02 result after adding one string to another is : 5402
- Related Articles
- Add one polynomial to another in Python
- Add one Chebyshev series to another in Python
- Add one Hermite series to another in Python
- Add one Laguerre series to another in Python
- Add one Legendre series to another in Python
- Add one Hermite_e series to another in Python
- Program to check one string can be converted to another by removing one element in Python
- Check if it is possible to transform one string to another in Python
- Program to check whether one string can be 1-to-1 mapped into another string in Python
- Java Program to construct one String from another
- Python Program to Insert a string into another string
- Subtract one polynomial to another in Python
- Multiply one polynomial to another in Python
- Add leading Zeros to Python string
- String Transforms Into Another String in Python

Advertisements