Python print() Fungsi
Contoh
Cetak pesan ke layar:
print("Hello World")
Definisi dan Penggunaan
Fungsi ini print()
mencetak pesan yang ditentukan ke layar, atau perangkat keluaran standar lainnya.
Pesan dapat berupa string, atau objek lain, objek tersebut akan diubah menjadi string sebelum ditulis ke layar.
Sintaksis
print(object(s),
sep=separator, end=end, file=file, flush=flush)
Nilai Parameter
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 |
Lebih Banyak Contoh
Contoh
Cetak lebih dari satu objek:
print("Hello", "how are you?")
Contoh
Mencetak tupel:
x = ("apple", "banana", "cherry")
print(x)
Contoh
Cetak dua pesan, dan tentukan pemisah:
print("Hello", "how are you?", sep="---")