How do you print output in Python?

In Python, you can use the print() function to display output. Simply pass the content you want to print as an argument to the print() function.

Here are some examples:

  1. Print a string.
print("Hello, World!")
  1. Print the value of the variable:
x = 10
print(x)
  1. Print the values of multiple variables.
x = 10
y = 5
print(x, y)
  1. Print the result of the expression:
x = 10
y = 5
print(x + y)
  1. Formatted output:
name = "Alice"
age = 25
print("My name is {} and I am {} years old.".format(name, age))

Please note that the print() function has other parameters such as sep and end, which can be used to control the separator and ending character of the output. You can refer to the official Python documentation for more information about the print() function.

bannerAds