وظيفة طباعة بايثون ()
مثال
اطبع رسالة على الشاشة:
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)
مثال
اطبع رسالتين وحدد الفاصل:
print("Hello", "how are you?", sep="---")