1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonで「print関数の使い方(文字列を出力する)」の動作を確認してみた

Posted at

概要

Pythonで「print関数の使い方(文字列を出力する)」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.py
print("Hello")
print(256)
print("Blue", "Red", "Green")

# デフォルトの設定
print("Blue", "Red", "Green")
# 区切り文字を "+" に変更
print("Blue", "Red", "Green", sep="+")
# 区切り文字を無くして続けて出力
print("Blue", "Red", "Green", sep="")

# デフォルトの設定
print("Hello");print("Python")
# 改行しないように設定:
print("Hello", end="");print("Python")
# 最後に任意の文字列を出力するように設定
print("Hello", end="[end]\n")

myfile = open("output1_4.txt", "w")
print("Hello", file=myfile)
print("Bye", file=myfile)
myfile.close()

以下のコマンドを実行しました。

$ python3 sample.py 
Hello
256
Blue Red Green
Blue Red Green
Blue+Red+Green
BlueRedGreen
Hello
Python
HelloPython
Hello[end]
$ cat output1_4.txt 
Hello
Bye

まとめ

何かの役に立てばと。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?