Python print() 組み込み関数
オブジェクトを指定されたテキストストリームファイルに出力します。オブジェクト間は sep で区切られ、末尾には end が付きます。sep、end、file、および flush が指定された場合は、キーワード引数として渡す必要があります。
Introduction
print() 関数は、渡された引数の値を書き出します。[…] 複数の引数、浮動小数点数、および文字列を処理します。文字列は引用符なしで出力され、項目間にはスペースが挿入されるため、きれいに整形できます。
print('Hello world!')
Hello world!
a = 1
print('Hello world!', a)
Hello world! 1
The end keyword
キーワード引数 end を使用すると、出力後の改行を回避したり、出力を別の文字列で終了させたりできます。
phrase = ['printed', 'with', 'a', 'dash', 'in', 'between']
for word in phrase:
print(word, end='-')
printed-with-a-dash-in-between-
The sep keyword
キーワード sep は、オブジェクトが複数ある場合に、それらをどのように区切るかを指定します。
print('cats', 'dogs', 'mice', sep=',')
cats,dogs,mice