Python print() Functie
Voorbeeld
Een bericht op het scherm afdrukken:
print("Hello World")
Definitie en gebruik
De print()
functie drukt het gespecificeerde bericht af op het scherm of op een ander standaard uitvoerapparaat.
Het bericht kan een string zijn, of een ander object, het object zal worden omgezet in een string voordat het naar het scherm wordt geschreven.
Syntaxis
print(object(s),
sep=separator, end=end, file=file, flush=flush)
Parameterwaarden
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 |
Meer voorbeelden
Voorbeeld
Print meer dan één object:
print("Hello", "how are you?")
Voorbeeld
Een tupel afdrukken:
x = ("apple", "banana", "cherry")
print(x)
Voorbeeld
Druk twee berichten af en geef het scheidingsteken op:
print("Hello", "how are you?", sep="---")