Printing Text
The print() function is how your program talks to you. It displays text in the terminal, letting you see what's happening inside your code. This simple function will become one of your most-used tools.
Your First Print Statement
To display text, put it inside print() with quotes around it:
print("Hello")
Run this, and you'll see Hello appear in your terminal. The quotes tell Python that this is text data – what programmers call a string.
Single or Double Quotes – Both Work
Python accepts either single or double quotes for strings:
print("Hello")
print('Hello')
Both produce the same output. Most Python programmers prefer double quotes, but consistency matters more than which style you choose. Pick one and stick with it.
Printing Multiple Items
You can print several things at once by separating them with commas:
print("Hello", "World")
This outputs Hello World – Python automatically adds a space between items. This is handy when mixing text with variables:
name = "Alice"
print("Hello", name)
Creating Blank Lines
Sometimes you want visual spacing in your output. An empty print() creates a blank line:
print("First section")
print()
print("Second section")
This makes output easier to read, especially when displaying multiple pieces of information.
Print as a Debugging Tool
Here's something experienced programmers know: print() is your primary debugging tool. When code doesn't work as expected, adding print statements helps you see what's actually happening:
x = 10
print("x is:", x)
x = x + 5
print("after adding 5, x is:", x)
This technique – called "print debugging" – helps you trace through your code step by step. You'll use it constantly, even as you learn more sophisticated debugging methods.
Why This Matters
Every program needs to communicate results somehow. Whether you're building a calculator, processing data, or creating a game, print() lets you see what your code produces. It's also how you'll verify that your programs work correctly as you learn.
Start experimenting. Try printing your name, your favorite number, or a silly message. The more you use print(), the more natural it becomes.