- 字符串的拼接
字符串拼接是将多个字符串连接在一起形成一个新的字符串。在Python中,可以使用加号运算符(+)来实现字符串的拼接。
str1 = "Hello,"
str2 = " world!"
result = str1 + str2
print(result) # 输出: Hello, world!
- 字符串的分割
字符串的分割是将一个字符串按照指定的分隔符进行分割,并返回一个包含分割后子字符串的列表。在Python中,可以使用split()
函数来实现字符串的分割。
str1 = "Hello,"
str2 = " world!"
result = str1 + str2
print(result) # 输出: Hello, world!
split()
函数来实现字符串的分割。