Your First Python Program: print, Comments, sep and end
Five tiny files: print and quotes, top-to-bottom order, # comments, several values with sep and end, and the SyntaxError one missing quote causes. Every output is from a real run.
What you will learn
- Show text with print and explain what the quotes do
- Predict output by reading a file from top to bottom
- Use # comments to leave notes and switch a line off
- Change what print puts between and after values with sep and end
Before you start
- Nothing installed yet; you can read along first
Your first Python program starts with one small word: print. Every example you'll ever see in this library shows its result with print, so once you can read a print line, you can read what every example is telling you.
Before any code, think about a note you leave for a friend on how to make tea. A few short lines, in order: boil the water, add the tea, pour it into a cup. Your friend reads the first line and does it, then the second, then the third.
A Python program is the same kind of note. It's a text file of instructions, and Python carries them out. There's one difference. A friend can guess what you meant when you make a spelling mistake. Python can't, and you'll see that at the end.
Your first print
Here's hello.py:
print("Hello, world!")
print("My first Python program")
Hello, world!
My first Python program
print tells Python to show something. The brackets hold what you want to show. The double quotes mark where the text starts and ends, so Python knows this part is text and not an instruction.
Look at the output: the text comes out exactly as typed, comma included, but the quotes don't come out with it. The second print lands on its own line. Two lines of code, two lines of output, and that's a complete program.
Python reads from top to bottom
print("Step 1: wake up")
print("Step 2: make tea")
print("Step 3: start coding")
Step 1: wake up
Step 2: make tea
Step 3: start coding
Python starts at line one and shows "Step 1: wake up". Only then does it move to line two, then line three. After that there are no more lines, so the program ends. The order you write is the order you get.
Comments: notes Python skips
Sometimes you want to leave a note for the people reading your code. That's a comment, and it starts with a hash sign.
# This line is a note for people, Python skips it
print("Before the comment")
# print("This line is switched off")
print("After the comment") # a note can sit here too
Before the comment
After the comment
Python skips everything after a #. Line one does nothing at all. Line three is a print, but with a hash in front it's switched off, which is handy when you want to stop a line without deleting it. On the last line, Python runs the code and then skips from the hash onwards.
Three hash signs in the file, and only two lines of output.
Several values, sep and end
So far each print has shown one piece of text. You can give it more than one, separated by commas:
print("Tea", "and", "toast")
print("10", "30", sep=":")
print("Loading", end="...")
print("done")
print(2 + 3)
print("2 + 3")
Tea and toast
10:30
Loading...done
5
2 + 3
Line by line:
print("Tea", "and", "toast")puts a space between the values on its own. We never typed those spaces.sepis short for separator: what goes between the values. Withsep=":", a colon goes in instead of a space, so 10 and 30 come out as10:30.endis whatprintwrites after the last value. Normally that's a new line, which is why every print so far got its own line. Withend="...", print writes three dots and stays on the same line, so the nextprint("done")lands right beside it.print(2 + 3)has no quotes, so Python works it out and shows 5.print("2 + 3")is in quotes, so it's only text and comes out exactly as typed.
One missing quote
Now break something on purpose. In missing_quote.py the text opens with a quote but never closes:
print("Hello, world!)
print("This line never runs")
File "S01L01_1_FirstProgram\missing_quote.py", line 1
print("Hello, world!)
^
SyntaxError: unterminated string literal (detected at line 1)
A friend would guess what you meant. Python doesn't guess; it can't find where the text ends. So you get a SyntaxError saying the text was never closed, and Python tells you where it stopped: line 1.
Look at what didn't happen, too. Line two is fine, but it never ran. Python reads the whole file first, and one typo stops the program. Put the closing quote back and it's the same line that worked in hello.py.
An error isn't a disaster. Python stopped, told you where, and you fix that spot. You'll read errors properly in Run a Python file and read the error.
Common mistakes
- Forgetting the closing quote. You get
SyntaxError: unterminated string literal. - Expecting the quotes in the output. They only mark the text; they never print.
- Putting a number in quotes when you want Python to work it out.
"2 + 3"is text,2 + 3is 5.
Quick recap
| You write | You get |
|---|---|
print("Hello, world!") | the text, without quotes |
# a note | nothing; Python skips the rest of the line |
print("Tea", "and", "toast") | values with spaces between |
sep=":" | a colon between values instead |
end="..." | three dots instead of a new line |
| a missing quote | SyntaxError, and nothing runs |
Try it yourself
Once your setup is done (see Set up PyCharm for Python), open hello.py and print your name and one line about yourself.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Python for AI: The Five Tools You Actually Need
The small part of Python that carries most AI code: dicts and JSON, typed functions with a dataclass, comprehensions and f-strings, environment variables for keys, and try/except for replies that are not JSON. Three standard-library scripts on four support tickets.
Thinking Like a Python Architect in an AI-First World
Coding is laying bricks; architecting is deciding how the pieces fit. A two-line average function shows why someone still has to understand the code an AI tool writes.
Set Up PyCharm for Python: Install, First Project and First Run
Install PyCharm, create a Pure Python project, and understand the two words that confuse beginners: the interpreter (the cook) and .venv (the project's own shelf). Then run a file and read the exit code.
Run a Python File and Read the Error: Tracebacks in Three Steps
Run a file two ways, then break it on purpose. A NameError, an IndentationError, a TypeError and a three-frame traceback across two files, all read the same way: last line, line number, fix.
