Python-如何在段落之间创建空格?

时间:2018-08-14 16:21:51

标签: python

我是Python编程的初学者。当我编写代码时,它真的很长,因为我一直在段落下使用print('')来创建空间。到目前为止,我的编程工作是为即将上学年的老师妹妹做一些简单的测试。有没有更清洁,更短的空间放置方法?

示例:

print('What is the answer for this question?')
print('')
print('')
print('answer')

3 个答案:

答案 0 :(得分:2)

可以使用转义字符\n添加换行符。例如:

print('What is the answer for this question?\n\nanswer')

在输出上等同于示例代码。

答案 1 :(得分:1)

使用\n插入新行:

print('What is the answer for this question?\n\n')
print('answer')

如果您不想打印新行,可以使用以下命令:

print('What is the answer for this question? ',end='')

答案 2 :(得分:0)

您可以在打印语句中使用 \ n 命令创建一个“输入”块。

输入:

print("This is how you can\nmake breaks!")

输出:

This is how you can
make breaks!