Python String Concatenation

In Python, you can add characters to a string using the plus operator (+). Here is the specific method:

  1. Combine strings and characters using the plus sign operator, for example:
string = "Hello"
char = "!"
new_string = string + char
print(new_string)  # 输出:Hello!
  1. come together
string = "Hello"
char = "!"
new_string = "".join([string, char])
print(new_string)  # 输出:Hello!

Please note that strings are immutable, meaning that you cannot directly modify a character in a string. Therefore, adding characters to a string actually creates a new string and connects the original string with the new character.

bannerAds