In this tutorial, learn how to combine two string variables in Python. The short answer is: use the plus(+) operator to concatenate two string variable. Concatenation is the process of combining two or more string variables.
However, we will learn about combining only two variables with the example given here. You can combine the string enclosed within a single quote or double quote. Both quotes are the way to define a string. You may also like to learn how to create a string variable in Python.
How to Combine Two String Variables in Python
If you want to concatenate or combine two string variables in Python. You have to use the plus(+) operator with the string variables.
This is the addition of the two string variables. But it’s not a mathematical calculation or any other formation of evaluation. This just places the string with each other with first string followed by the second.
Str1 = "How are you?";
Str2 = "I am fine thank you.";
print(Str1 + Str2);
The output of the above string gives the combined output. You can place the two string variables with plus(+) operator directly to the print statement. Also, you can store the combination in the third string variable. After combination, you have to use the print statement to print the concatenated string in Python.
You may also like to read
- How to remove all whitespace from a string using Python
- convert all string to lowercase in Python
- Access string character by index using Python
- How to change string to uppercase in Python
Hope, you like this tutorial of how to combine two string variables in Python. If you have any query regarding the tutorial, please comment below.
Also tell me, which method you are using to concatenate the two string variables in Python.