簡體   English   中英

Python-如何在段落之間創建空格?

[英]Python-How to create spaces between paragraphs?

我是Python編程的初學者。 當我編寫代碼時,它真的很長,因為我一直在段落下使用print('')來創建空間。 到目前為止,我的編程工作是為即將上學年的老師妹妹做一些簡單的測試。 有沒有更清潔,更短的空間放置方式?

例:

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

可以使用轉義字符\\n添加換行符。 例如:

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

與示例代碼的輸出等效。

使用\\n插入新行:

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

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

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

您可以在打印語句中使用\\ n命令來創建一個“輸入”塊。

輸入:

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

輸出:

This is how you can
make breaks!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM