In Python, we can add two strings. The process of combining two strings is called concatenation. Two strings, whether created using single or double quotes, are concatenated in the same way.
Python Concatenation Examples
Example: 1
a="Apple is Red." b="Apple is also Green." c=a+b print(c)
Output:
Apple is Red.Apple is also Green.
We can also add numbers as a string. However, adding a string to a number generates an error.
Example: 2
a="Pyton" b=3.4 c=a+b print(c)
Output:
Error
Here we are concatenating a string and a number; an error is generating.
Example: 3
a="12" b="34" c=a+b print(c)
Output:
1234
Here the above program concatenates two numbers that are represented as strings.
Leave a comment