Your First Program
What you'll learn: How to write and run the classic "Hello, World!" program in Python.
Writing Your First Line of Code
Now that you have Python installed and VS Code set up, it's time to write your very first program! The tradition in programming is to start with something simple that displays text on the screen.
Open VS Code and create a new file called hello.py (the .py extension tells your computer this is a Python file). Inside this file, type exactly this:
print('Hello, World!')
That's it! This single line is a complete Python program.
What This Does
Think of print() as a command that tells Python to show something on the screen—like pressing a button that makes text appear. The words inside the quotation marks are what you want to display. You can use single quotes ('...') or double quotes ("..."), but they must match on both sides.
Running Your Program
To run your program:
- Save the file (Ctrl+S on Windows/Linux, Cmd+S on macOS)
- Open VS Code's terminal (usually at the bottom of the window)
- Type
python hello.pyand press Enter
You should see Hello, World! appear in the terminal. Congratulations—you just wrote and ran your first Python program!
Try It Yourself
Change the text between the quotes to anything you want: your name, a favorite quote, or a silly message. Save and run it again. Each time you run the program, Python reads your code from top to bottom and follows your instructions.
Key Takeaway: The print() command displays text on the screen, and you can run any Python file by typing python filename.py in your terminal.