Python Setup and Your First Program
Setup and Your First Program
Before diving into Python syntax, let's get your development environment ready. All you need is Python installed and a text editor.
Installing Python
Windows
- Go to https://python.org and click Downloads
- Download the latest Python version (e.g., 3.13.x)
- Run the installer — make sure to check "Add Python to PATH"
- Open Command Prompt (cmd) and verify with
python --version
C:\Users\YourName> python --version
Python 3.13.2
Mac
Mac comes with Python 2 (too old), so you need to install Python 3:
- Go to https://python.org and download the Mac installer
- Run the installer, or use Homebrew:
brew install python3 - Verify in the terminal:
python3 --version
Linux
Most Linux distributions already have Python 3 installed:
BASH
# Ubuntu/Debian
sudo apt install python3
# Verify
python3 --version
Hello World Program
Once installed, your first program is always "Hello, World!".
Method 1: Interactive Interpreter
Type python (Windows) or python3 (Mac/Linux) in your terminal to enter interactive mode:
PYTHON
Python 3.13.2 (main, Feb 4 2025, 14:51:09)
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Hello, World!
>>> 1 + 2
3
>>> exit()
💡 The interactive interpreter is great for quickly testing code snippets, but not ideal for writing complete programs.
Method 2: Create a .py File
- Create a new file called
hello.py - Enter this code:
PYTHON
print("Hello, World!")
- Run it from the terminal:
BASH
python hello.py
Output:
Hello, World!
Choosing an Editor
You don't need a complex IDE when you're just starting out. Here are some recommendations:
| Editor | Best For | Pros |
|---|---|---|
| VS Code | Beginners (recommended) | Free, lots of extensions, lightweight |
| PyCharm | Professional development | Most features, great autocomplete |
| IDLE | Absolute beginners | Comes with Python, ready out of the box |
| Jupyter Notebook | Data analysis | Run code in cells, great for interactive learning |
💡 We recommend VS Code with the Python extension — lightweight and powerful.
VS Code Setup
- Download and install VS Code (code.visualstudio.com)
- Open VS Code, press
Ctrl+Shift+Xto open the Extensions panel - Search for "Python" and install Microsoft's official Python extension
- Create a new file and save it with a
.pyextension - Right-click in the editor → "Run Python File in Terminal"
Your First Complete Program
Let's put it all together and write a small interactive program:
PYTHON
# First Python program
name = input("What's your name? ")
print("Hello, " + name + "! Welcome to Python!")
When you run it:
What's your name? Alice
Hello, Alice! Welcome to Python!
Common Pitfalls
- PATH not set (Windows): You MUST check "Add Python to PATH" during installation, otherwise the terminal won't find the
pythoncommand - python vs python3: Windows uses
python, Mac/Linux usepython3 - Chinese encoding issues: Python 3 uses UTF-8 by default, so garbled text is rare. If you do run into encoding issues, add
# -*- coding: utf-8 -*-at the top of your file
📖 Section Summary
- Download and install Python 3.x from python.org
- On Windows, check "Add Python to PATH" during installation
- Interactive interpreter: type
pythonin the terminal .pyfiles: write code in an editor, run withpython filename.py- VS Code + Python extension is the recommended development setup
📝 Homework
- Install Python and type
python --versionin the terminal — take a screenshot - Write a
hello.pyfile that prints"Hello, World!"and run it successfully - In the interactive interpreter, calculate
(5 + 3) * 2and10 / 3— observe the results - Modify the interactive program above by adding an
agevariable, and print "Your name is XX, you are XX years old"



