The print() function is often the very first line of Python code beginners write:
print("Hello, world!")
But there's more power packed into print() than most realize.
What is print()?
In Python, print() is a built-in function that outputs text or other data to the console. It's commonly used for debugging, displaying results, and providing user feedback.
🛠️ Basic Usage
print("This is Python.")
This is Python.
You can also print numbers and variables:
name = "Alice"
print("Hello", name)
Hello Alice
📌 Separator (sep) and End (end) Parameters
You can customize the way multiple items are separated and how the line ends.
print("Python", "is", "awesome", sep=" - ")
Python - is - awesome
print("This is", end=" >> ")
print("a chained print.")
This is >> a chained print
🔄 Print with Formatting
You can format your output using f-strings:
age = 25
print(f"I am {age} years old.")
I am 25 years old.
📝 Final Thoughts
print() is simple yet incredibly versatile. Whether you're learning Python or building large-scale apps, mastering print() will make your coding life much smoother.
👉 If you liked this post, leave a like and follow me for more Python tips and tutorials!
Top comments (0)