Python Оператор Print(): як друкувати з прикладами

⚡ Розумний підсумок

Python print() function displays a message or object on the screen after converting it to a string. The examples below show how to print strings, blank lines, and multiple items, and how to control line endings.

  • 🖨️ Мета: The print() function outputs strings and objects to the screen.
  • 🔤 Синтаксис: Call print(object(s)) with the value you want to display.
  • 🔁 Multiple Prints: Each print() call outputs on its own new line by default.
  • Blank Lines: Use “\n” or multiply it to print empty lines.
  • ➡️ end Parameter: Change the line ending, for example end=’ ‘, in Python 3.
  • ⚠️ Примітка до версії: Python 3 uses print() as a function; Python 2 used it as a statement.

Python Print() Statement

Python функція print ()

Функція print() в Python використовується для друку вказаного повідомлення на екрані. Команда друку в Python друкує рядки або об'єкти, які перетворюються на рядок під час друку на екрані.

Синтаксис:

print(object(s))

Як надрукувати простий рядок Python?

Частіше не потрібно Надрукувати рядки у вашій конструкції кодування.

Ось як надрукувати виписку Python 3:

Приклад: 1

Щоб роздрукувати вітальне повідомлення Guru99, використовуйте Python надрукувати заяву наступним чином:

print ("Welcome to Guru99")

вихід:

Ласкаво просимо до клініки Guru99

In Python 2, такий самий приклад буде виглядати

print "Welcome to Guru99"

Приклад 2:

Якщо ви хочете надрукувати назву п’яти країн, ви можете написати:

print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")

вихід:

USA
Canada
Germany
France
Japan

Як друкувати порожні рядки

Іноді вам потрібно надрукувати один порожній рядок у вашому Python програма. Нижче наведено приклад виконання цього завдання Python формат друку.

приклад:

Виведемо 8 порожніх рядків. Ви можете ввести:

print (8 * "\n")

або:

print ("\n\n\n\n\n\n\n\n\n")

Ось код

print ("Welcome to Guru99")
print (8 * "\n")
print ("Welcome to Guru99")

Вихід

Welcome to Guru99







Welcome to Guru99

Команда завершення друку

By default, the print function in Python ends with a newline. This function comes with a parameter called ‘end’. The default value of this parameter is ‘\n’, i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available only in Python 3 +.

Приклад 1:

print("Welcome to", end=' ')
print("Guru99", end='!')

вихід:

Ласкаво просимо до клініки Guru99!

Приклад 2:

# ends the output with '@'
print("Python", end='@')

вихід:

Python@

Поширені запитання

In Python 2, print was a statement written as print “text”. In Python 3, print is a function called as print(“text”) with parentheses. Python 3 is the current standard, so always use the function form.

The sep parameter sets the separator placed between multiple items in one print() call. By default it is a space. For example, print(“a”, “b”, sep=”-“) outputs a-b instead of a b.

Use an f-string, such as print(f”Hello {name}”), or separate items with commas, such as print(“Hello”, name). F-strings are the modern, readable way to mix text and variables in Python 3.6 і пізніше.

Yes. AI assistants can spot missing parentheses, wrong quotes, or Python 2 syntax, and explain the exact error. They also suggest cleaner ways to format output, which helps beginners fix print-related mistakes quickly.

print() is a simple way to inspect data, model outputs, and intermediate values while building AI programs. Developers use it to trace how data flows through code, though logging libraries are preferred for larger projects.

Підсумуйте цей пост за допомогою: