python怎么连接两个字符串并输出
要连接两个字符串并输出,可以使用加号 +
运算符或者使用字符串的 join()
方法。
使用加号运算符:
str1 = "Hello"
str2 = "World"
result = str1 + " " + str2
print(result)
使用join()
方法:
str1 = "Hello"
str2 = "World"
result = " ".join([str1, str2])
print(result)
两种方法都会输出:
Hello World
阅读剩余
THE END