Skip to content

Python Foundations·Lesson 1 of 67·beginner

Your first program

Run real Python in your browser, understand what print actually does, and meet the error message you will see most often.


In this lesson · 8 min

  • →Run a Python program and read its output
  • →Understand the difference between an expression and a statement
  • →Read a SyntaxError and fix it

Python runs your file one line at a time, top to bottom. There is no build step and no main function to declare — the first line is where execution starts.

Here is a complete Python program. Press Run (or Ctrl/Cmd + Enter).

PythonPython not started

print is a function, and print("Hello, World!") is a call. The parentheses mean “run this now”, and the thing between them is the argument you’re passing in.

print takes as many arguments as you like and separates them with a space:

PythonPython not started

Notice you can pass numbers and True alongside text — print converts whatever it’s given into something readable. That’s a convenience of print specifically, not a rule of the language, as you’ll see in the next lesson.

Statements run in order

Each line here is a statement — an instruction. Python runs them strictly top to bottom.

PythonPython not started

Reorder those lines and run it again. The output order follows the source order exactly. This sounds obvious, but it is the single most useful debugging tool you have: when something goes wrong, add a print and find out how far execution actually got.

Your first error

Python is strict about syntax. Leave off a closing parenthesis and it refuses to run any of the file — not even the lines before the mistake.

PythonPython not started

Read the error from the bottom up. The last line names the problem — SyntaxError: '(' was never closed — and the lines above point at where Python gave up.

Fix the code above by adding the missing ) and run it again.

Comments

A # makes Python ignore the rest of the line. Comments are for the human reading the code — usually you, in three months.

PythonPython not started

Try it yourself

Exercise 1

Print exactly three lines: ready, set, then go.

Your turnPython not started

Check yourself

Which of these prints a blank line?

Recap

  • Python executes statements top to bottom, starting at line 1.
  • print(...) is a function call; the parentheses are what makes it run.
  • # starts a comment, which Python ignores entirely.
  • A SyntaxError stops the whole file from running — fix it before anything else.