Using the + operator lets you concatenate characters in Python. This operator is referred to as the Python string concatenation operator
Example concatenate characters in Python
Simple example code using + operator between to characters.
res = 'a' + 'b' + 'c' print(res) print(type(res))
ch1 = "a" ch2 = "b" res = ch1 + ch2 print(res)
Alternatively, if you have a collection of characters, such as a list or tuple, you can use the
join() method to concatenate them. Here’s an example:
# Concatenating characters using join() characters = ['H', 'e', 'l', 'l', 'o'] concatenated = ''.join(characters) print(concatenated) # Output: Hello
In this case, we create a list
characters containing the individual characters. Then, using the
join() method with an empty string
'', we concatenate the characters together, resulting in the same output
Comment if you have any doubts or suggestions on this Python concatenate topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.