>>> a = "string1"
>>> b = "string2"
>>> print(ab) ## 直接输出报错 Traceback (most recent call last): File "<pyshell#33>", line 1, in <module> print(ab) NameError: name 'ab' is not defined >>> ab = f"{a} {b}" ## 使用f合并字符串
>>> print(ab) string1 string2 >>> print(ab,"strints") string1 string2 strints >>> print(f"{ab} strints") string1 string2 strints
>>> print("xxxx") xxxx >>> print("yyyy") yyyy >>> print("xxxx""yyyy") xxxxyyyy >>> print("xxxx","yyyy") xxxx yyyy >>> a = "mmmm"
>>> b = "nnnn"
>>> c = "oooo"
>>> print(bc) Traceback (most recent call last): File "<pyshell#111>", line 1, in <module> print(bc) NameError: name 'bc' is not defined >>> print(b,c) nnnn oooo >>> print(a,b,c) mmmm nnnn oooo