In this post, we will study Python Strings Concatenation example. String are very useful in any programming language, so in Python Programming too. Below we will see how to concatenate two or more Strings in Python.
In Python, Strings can be concatenate with Plus sign +. Let’s see below Python Strings Concatenation example
Example
#Python Strings concatenation Example str1="Python tutorial " str2="for beginners" str3=str1+str2 print(str3)
Output
Python tutorial for beginners
Explanation
- Here str1 and str2 are two String when we concatenate str1 and str2 with plus + sign, these strings will merge into one and we store that String into str3.
- String str3 will also be a String, you can check this by using type() function of Python. when you will write
print(type(str3))
result will be<class 'str'>
we can only concatenate Strings using plus operator. If we concatenate String with Integer using plus, It will throw error.
#Python String concatenation Example str1="Python tutorial " num1=1 str3=str1+num1 print(str3) print(type(str3))
TypeError: must be str, not int
Please follow and like us:
[…] python if we use plus + sign between two Strings, they will concatenate as we study in Python Strings concatenation example , and if we apply plus operator between two numbers, numbers will […]