编写一个 Python 程序来连接字符串,并附带实际示例。此程序允许用户输入两个不同的字符串。接下来,我们使用算术运算符“+”来连接这两个字符串。
str1 = input("Please Enter the First String : ")
str2 = input("Please Enter the Second String : ")
concat1 = str1 + str2
print("The Final String After Python String Concatenation = ", concat1)
concat2 = str1 + ' ' + str2
print("The Final After String Concatenation with Space = ", concat2)

如果要连接字符串字面量,可以使用以下方法。这两种 Python 方法都可以使用,即带括号或不带括号。
concat1 = 'Tutorial ' 'Gateway'
print("The Final String = ", concat1)
concat2 = ('Python ' 'Programming ' 'Examples')
print("The Final String = ", concat2)
字符串连接输出
The Final String = Tutorial Gateway
The Final String = Python Programming Examples