Python:如何在字符串之间添加空格

2024-04-26 14:43:00 发布

您现在位置:Python中文网/ 问答频道 /正文

更具体地说,我正试图以类似soprint str(function(first)) + str(function(second)) + str(function(third))等句子的形式打印函数的几个结果,但我遇到了一个问题,即各个字符串之间没有空格。你知道吗

所以,我想知道的是如何在每个字符串之间添加空格。你知道吗


Tags: 字符串function形式句子first空格secondstr
3条回答
print function(first), function(second), function(third)

或使用字符串格式:

print '{0} {1} {2}'.format(function(first), function(second), function(third))
print str(function(first)) + ' ' + str(function(second)) + ' ' + str(function(third))

使用join()

print " ".join([str(function(first)), str(function(second)), str(function(third))])

相关问题 更多 >