How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Python concatenate strings operator with basic syntax and many examples for better understanding.
Python concatenate strings (+) operator is used to add two strings and create a new string value. We can update the string by using concatenation.
Syntax:
(string_variable_name1) + (string_variable_name2) + (string_variable_name3) + .......
Input Parameters:
- string_variable_name1 & string_variable_name2 : The string that we want to be concatenated.
Example (1)
#Add 3 strings
print('Added string:', 'Python'+'V'+ str(3.78))
Output of example (1)
Added string: PythonV3.78
In the above Example, by using the concatenation operator (+), we have added three strings as two string values and one float value, which is converted into a string, and after applying concatenation on them output shows value as ‘PythonV3.78’.
Example (2)
#Add string with string variable
str1='Python'
print ('Added string variable:',str1[:2]+'pi'+str1[4:])
Output of example (2)
Added string variable: Pypion
In the above Example, we have added two slicing string variable with one string value and after applying concatenation on them, the output shows value as ‘Pypion’, which includes result of str1[:2]=’Py’ and str1[4:]=’on’.
Note: Concatenation operator implies that both the operands passed must be string else error will be shown.
In this tutorial, you have learned how to concatenate two or more strings in python.
If you have an inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback.But remember to understand the concept very well, you need to practice more.
Hopefully, it was clear and concise.
Similar Python operators:
- Repetition(‘*’) : It repeats element of string.
- Membership(‘in’ & ‘not in’) : It returns True , if given element is present in string otherwise returns False.
- String Iteration : It returns element of string by using for loop with string.
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials : access all python tutorials.