How to print content in Python?
To print content in Python, you can use the print() function. Here are a few examples:
- Print the string:
print("Hello, World!")
- Print the value of the variable:
name = "Alice"
print(name)
- Print multiple elements:
age = 25
print("My name is", name, "and I am", age, "years old.")
- Print formatting:
print("My name is {} and I am {} years old.".format(name, age))
- 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.