Introduction to print()
The print() function in Python is one of the most fundamental and frequently used functions. It outputs text and variables to the console.
print("Hello, World!")
Hello, World!
The print() function in Python is one of the most fundamental and frequently used functions. It outputs text and variables to the console.
print("Hello, World!")
Control output formatting with sep and end parameters:
print("Hello", "World", sep="-", end="!")
Use f-strings and format specifiers:
name = "Python"
print(f"I love {name}!")
Python's print function can easily display variables of any type. Variables are automatically converted to their string representation.
number = 42
name = "Python"
print(number)
print("Value:", number)
print(f"I love {name}!")
age = 25
print("Age:", age)
Use multiple arguments to print several items at once:
print("Python", "is", "awesome")