| sidebar_position | 4 |
|---|
The print function in Python is used to display messages on the console. You can pass any value to it, and it will convert it to a string and print it. If you want to print multiple items, you can separate them with commas. By default, there is no separator, but you can add one using the sep argument. Additionally, each print statement ends with a new line, but you can change this using the end argument.
print("Welcome to Python!")print("Python", "is", "fun")Output: Pythonisfun
print("Python", "is", "fun", sep=" ")Output: Python is fun
print("Hello", end="-")
print("World")Output: Hello-World
print("Learn", "Python", sep="\*", end="!")
print("It's great")Output: Learn*Python!It's great
These examples should help you understand how to use the print function effectively.