Python Programming
Setting Up Python
Step 1: Install Python
- Visit python.org/downloads and download the latest Python version (3.11 or newer).
- Windows: Run the installer and CHECK the box 'Add Python to PATH' before clicking Install.
- Mac: The installer will guide you through the process.
- To verify installation, open Command Prompt (Windows) or Terminal (Mac) and type: `python –version`. You should see the Python version number.
Step 2: Choose Your Code Editor
- A code editor is where you'll write your Python programs. Here are the best free options:
- VS Code (Recommended): Download from code.visualstudio.com. Install the Python extension from the Extensions panel.
- PyCharm Community Edition: Download from jetbrains.com/pycharm. Great for beginners with helpful features built-in.
- IDLE: Comes pre-installed with Python. Simple and good for learning basics.
Step 3: Your First Python Command
- Open your terminal/command prompt and type `python` (or `python3` on Mac). You'll see `>>>` which means Python is ready.
- Type: `print('Hello, World!')` and press Enter.
- Congratulations! You just ran your first Python code! Type `exit()` to leave Python.
Step 4: Create Your First Python File
- Open VS Code or your chosen editor.
- Create a new file and save it as `hello.py` (.py is the Python file extension).
- Type: `print('I am learning Python!')` and save the file.
- Run it from terminal: Navigate to the file location and type `python hello.py`. You'll see your message!
Troubleshooting Tips
- 'python' is not recognized: You need to add Python to your PATH. Reinstall Python and check the 'Add to PATH' option.
- Editor not finding Python: In VS Code, press Ctrl+Shift+P, type 'Python: Select Interpreter', and choose your installed Python version.