2017-08-20 5 views
1

改行を単にpythonで印刷したいのであれば、print('')、またはprint('\n', end = '')などを使用する方が良いでしょうか?改行を印刷するための適切なフォーム(Python)

print('\n', end = '')が複雑に見えますが、print('')は少し奇妙です。あなたは、単に改行文字を印刷する必要がある場合、のpython3使用

+1

私が見る限り印刷物には何も問題ありません。また、前のprintステートメントに '\ n'を追加することもできます。 – davo36

+1

Python 2または3?あなたはその構文を混ぜています。 –

+1

これらの回答の1つが役に立った場合は、[それを受け入れてマークする](https://stackoverflow.com/help/someone-answers)をしてください。 –

答えて

0

は、その後、あなたが使用します。

print()

print()のドキュメントを見ると、それはデフォルト end文字が '\n'であることを示しています。

print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) 

Prints the values to a stream, or to sys.stdout by default. 
Optional keyword arguments: 
file: a file-like object (stream); defaults to the current sys.stdout. 
sep: string inserted between values, default a space. 
end: string appended after the last value, default a newline. 
flush: whether to forcibly flush the stream. 
Type:  builtin_function_or_method 
関連する問題