如何在变量后立即打印标点符号?蟒蛇

1 python printing string punctuation

s = "A Colon is beside me"
print s,":"
Run Code Online (Sandbox Code Playgroud)

我应该得到

科隆在我旁边:

但我想得到

>>>A Colon is beside me:
Run Code Online (Sandbox Code Playgroud)

怎么样?

Mar*_*ers 7

连接字符串:

print s + ':'
Run Code Online (Sandbox Code Playgroud)

或使用字符串格式:

print '{0}:'.format(s)
Run Code Online (Sandbox Code Playgroud)

在python 3上,print()也可以告诉函数在多个参数之间使用空分隔符,而不是空格:

print(s, ':', sep='')
Run Code Online (Sandbox Code Playgroud)