Python的内容拼接方式

1,字符串拼接,使用“”+“”将2个字符串拼接起来,这种方法只适合字符串

A = 'A'

B = 'B'

C = A + B

print(C)

打印:

AB

2,逗号拼接,2个字符串之间使用,拼接

A="A"
B="B"

print(A,B)


打印
A B

3,直接拼接

print("A""B")


打印

AB

4,format 拼接

C = '拼接{},{}'.format('A','B')   #通过{}占位符占住位置,有几个内容就必须得有几个占位符
print(C)

打印

拼接A,B

猜你喜欢

转载自blog.csdn.net/m0_58002043/article/details/120994681