Modules/Python/ Your First Program

Hello, Python!

Your first program, run in a real Python interpreter that lives right here in the page. Change the code, press Run, and the browser actually executes it.

Your first line of code

Press Run and watch it print. Then edit the text inside the quotes and run again.


                        

A program with several steps

Python reads a file top to bottom, running each statement in turn. Two prints, and a calculation in between.


                        

How to read the output

print writes a value to the screen. It is how a program talks to you — everything else on this track builds on seeing what your code actually does.
Quotes mark text. print("Hello") prints Hello, not the quote marks — the quotes are part of the code, not the message.
No quotes means math. print(2 + 3) prints 5, because Python computes the addition before printing. Compare that with print("2 + 3"), which prints the text literally.
Order matters. Statements run top to bottom, one line at a time. Swap the two print lines in the second editor and the output order flips with them.

Hello, Python: A Practical Guide

Running code changes what you believe about it.

Quick Context

Python is an interpreted language: a program called the interpreter reads your file top to bottom and executes each statement immediately. There is no separate compile step, which is why the editor on this page can show you results the instant you press Run — the interpreter is running your code right in the browser.

The print function

print() is a function — a named chunk of work you call by writing its name and putting the input in parentheses. Whatever you hand it, it writes to the output. Try printing several things at once by separating them with commas: print("I am", 3, "steps ahead"). Notice Python inserts a space between the pieces for you.

Interactive Exploration Guide

  1. Edit the greeting. In the first editor, change the text inside the quotes to your own name and press Run.
  2. Break the quotes. Delete one of the quote marks and press Run. The error you get is Python complaining that it reached the end of the line while still reading a string — the single most common beginner error, and it is perfectly safe to make here.
  3. Numbers vs text. Replace "Hello, Python!" with 2 + 3 (no quotes) and run again. Then run print("2 + 3") and compare the two outputs.
  4. Reorder the steps. In the second editor, move the last print("Done!") to the top of the file and run. The output proves Python executed your lines in exactly the order you wrote them.

Key Takeaway

Everything a program does is the result of statements running top to bottom. print is your window into that — it turns invisible execution into text you can read. And the moment you can change code and see different output, you have moved from reading about programming to actually programming.

Check yourself

0 of 3

Answer without scrolling back up.

  1. What does print("Hello") send to the screen?

  2. print(2 + 3) prints:

  3. A program is just:

Cheat sheet

Hello, Python!

Your first program, run in a real Python interpreter that lives right here in the page. Change the code, press Run, and the browser actually executes it.

PYTHON · vizlearn.in/python/hello_python.html