Skip to main content

Your First Program!

This is it. You have installed Python and set up your smart notebook (VS Code). Now it is time to write your first line of code and give your computer its first instruction.


1. Create a Python File

  1. In VS Code, look at your Python_Learning folder on the left side.
  2. Click the New File icon (it looks like a piece of paper with a + symbol).
  3. Name your file hello.py and press Enter.

Why the .py? The .py at the end is very important! Just like a photo ends in .jpg and music ends in .mp3, putting .py tells your computer: "Hey, this is a Python file!"


2. Write Your Code

Click inside your empty hello.py file and type exactly this:

print("Hello, World!")

What does this line mean? The print() instruction tells the computer to take whatever is inside the quotation marks "" and show it on the screen. It is your way of making the computer talk to you!


3. Run Your Code

Now we need to tell Python to read our file and run our instruction.

  1. At the very top of VS Code, click Terminal -> New Terminal. A small black box will appear at the bottom of your screen.
  2. Click inside that black box, type this command exactly, and press Enter:
python hello.py

🎉 CONGRATULATIONS! 🎉

Look at the black box (terminal) at the bottom. Did it print Hello, World!?

If yes, you just successfully wrote and executed your first piece of software. You are officially a programmer!


Common Beginner Mistakes
  • Case Sensitivity: Print("Hello") with a capital P will fail. Python commands are always lowercase print().
  • Missing Quotes: print(Hello) will fail. Text must always be wrapped in quotes ("" or '').
  • Unsaved File: If you see a white dot next to hello.py in VS Code, press Ctrl + S to save before running.

4. Notes for Yourself (Comments)

As you start writing more code, you might want to leave notes for yourself or other programmers explaining what the code does. You can do this using Comments.

In Python, anything that comes after a hash symbol # is completely ignored by the computer. It is just text for humans to read!

# This is a comment. The computer will ignore this line.
print("Hello!") # You can also put comments at the end of a line

Quick Summary

  • File Extension: Python files must end with the .py extension (e.g., hello.py).
  • print() Function: The built-in command used to output text, numbers, and variables to the screen.
  • Terminal Execution: Run Python files using python filename.py inside the integrated terminal.
  • Comments (#): Explanatory notes for humans that Python ignores during execution.
  • Case Sensitivity: Python commands are strictly lowercase (print, not Print).

What's Next?

Now that you know how to give the computer basic instructions, let's learn how code actually runs behind the scenes in the next lesson!