Skip to content

Your First Program

Write a real script, run it, and change it. Use any text editor — Notepad works, though an editor that numbers lines (VS Code, Notepad++) makes life easier later.

(Commands below use python on Windows, python3 on Mac/Linux.)

1. The one-liner

Open a terminal and run Python with a command directly:

python -c "print('Hello, world!')"

Check: it prints Hello, world!. The -c flag means "run this code right now." print() displays whatever you give it.

2. A script file

One-liners get old fast. Create a file called hello.py containing:

print("Hello, world!")

Run it:

python hello.py

Check: same greeting. A script is just commands saved in a file — Python runs them top to bottom.

3. Make it yours

Change the file to:

name = "Ada"
print("Hello,", name)

Run it again.

Check: it prints Hello, Ada. You just used a variable — a named box holding a value. See Variables and Types.

4. Take input

name = input("Your name? ")
print("Hello,", name)

Check: the program waits, you type your name, it greets you. input() pauses for the keyboard and hands you what was typed — always as text, even if the user types digits.

What to try next

Sources