以下のコードに何か違いはありますか?
file = open("sample.txt", "w", encoding="utf-8")
print("hello", file=file)
file.write("hello")
file.close()
python3ではprint文でファイル書き込みができますが、使い分ける状況などはありますか?
スタック・オーバーフローはプログラマーとプログラミングに熱心な人のためのQ&Aサイトです。すぐ登録できます。
登録してこのコミュニティに参加する
print("hello", file=file)
とfile.write("hello")
に違いは有るか? という意味でしょうか? – nekketsuuu♦ 17年8月25日 16:35