Concatenation Operator + or ,

前端 未结 3 964
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 11:25
var1 = \'abc\'
var2 = \'xyz\'

print(\'literal\' + var1 + var2) # literalabcxyz
print(\'literal\', var1, var2) # literal abc xyz

... except for automat

3条回答
  •  眼角桃花
    2021-02-04 12:17

    Using a comma gives the print function multiple arguments (which in this case are printed all, seperated by a space. Using the plus will create one argument for print, which is printed in its entirety. I think using the + is best in this case.

提交回复
热议问题