How to print content in Python?

To print content in Python, you can use the print() function. Here are a few examples:

  1. Print the string:
print("Hello, World!")
  1. Print the value of the variable:
name = "Alice"
print(name)
  1. Print multiple elements:
age = 25
print("My name is", name, "and I am", age, "years old.")
  1. Print formatting:
print("My name is {} and I am {} years old.".format(name, age))
  1. Format printing using f-string in Python 3.6 and above.
print(f"My name is {name} and I am {age} years old.")

No matter how, the printed content will be displayed on the console when the code is executed.

bannerAds