print() 標準出力への出力
最終更新:2026-09-22
print() 標準出力への出力
print() は objects を文字列に変換して標準出力(デフォルト)に書き込む。sep は区切り、end は終端、file はリダイレクト。
| カテゴリ | 組み込み関数 |
|---|---|
| 種類 | 組み込み関数 |
| Python バージョン | all |
📝 構文
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
⚙️ 引数
| objects 任意 | Zero or more objects to print (variadic), converted to strings automatically. |
|---|---|
| sep 任意 | Separator inserted between objects, default a space.(デフォルト値:' ') |
| end 任意 | String appended at the end, default a newline.(デフォルト値:\n) |
| file 任意 | Output target; must have a write method.(デフォルト値:sys.stdout) |
| flush 任意 | Whether to flush the stream immediately.(デフォルト値:False) |
戻り値:Returns None; output is written to the stream given by file.
▶ 例
下のコードを編集し「実行」をクリックすると、出力パネルに結果が表示されます:
実行結果:
hello
a-b-c
no newline here
🏷️ 関連する組み込み関数
💡 関連するケース
さらに多くのケースは近日公開予定です。
❓ よくある質問
Qprint('a', 'b', 'c', sep='-') の出力はどうなりますか?
Aa-b-c と出力されます。sep は複数のオブジェクト間の区切り文字を指定し、既定値は空白です。
Q改行なしで出力するには?
Aend='' を渡します。print('x', end='') なら改行されず、次の print が同じ行に続きます。end の既定値は '\n' です。
Qprint() でファイルへ出力できますか?
Aできます。print('text', file=f) でファイルオブジェクトへ、print(..., file=sys.stderr) で標準エラー出力へ書き込めます。
Qprint() の戻り値は?flush 引数は何のため?
Aprint() は None を返すので、戻り値として使わないでください。flush=True はバッファの内容を即座に出力ストリームへ書き出し、進捗バーやリアルタイムログなど即時表示が必要な場面で使います。