Python print()関数
例
画面にメッセージを印刷します。
print("Hello World")
定義と使用法
このprint()
関数は、指定されたメッセージを画面またはその他の標準出力デバイスに出力します。
メッセージは文字列またはその他のオブジェクトにすることができ、オブジェクトは画面に書き込まれる前に文字列に変換されます。
構文
print(object(s),
sep=separator, end=end, file=file, flush=flush)
パラメータ値
Parameter | Description |
---|---|
object(s) | Any object, and as many as you like. Will be converted to string before printed |
sep='separator' | Optional. Specify how to separate the objects, if there is more than one. Default is ' ' |
end='end' | Optional. Specify what to print at the end. Default is '\n' (line feed) |
file | Optional. An object with a write method. Default is sys.stdout |
flush | Optional. A Boolean, specifying if the output is flushed (True) or buffered (False). Default is False |
その他の例
例
複数のオブジェクトを印刷します。
print("Hello", "how are you?")
例
タプルを印刷します。
x = ("apple", "banana", "cherry")
print(x)
例
2つのメッセージを印刷し、区切り文字を指定します。
print("Hello", "how are you?", sep="---")