Skip to content

Setting Up Python and Writing Your First Code

Shaswat Raj edited this page Dec 17, 2024 · 1 revision

🚀 Setting Up Python and Writing Your First Code

Welcome to Section 2 of Python One Shot for Beginners 2025! This guide will help you set up Python on your system and write your very first Python program.


🔧 Step 1: Install Python (Latest Version)

Python is easy to install on any operating system. For 2025, make sure you’re using Python 3.12 or higher for maximum compatibility.

Windows

  1. Go to the [official Python website](https://www.python.org).
  2. Download the latest Python installer for Windows.
  3. Important: During installation, check the box that says “Add Python to PATH”.
  4. Verify the installation by opening Command Prompt and typing:
    python --version
    If installed correctly, it will show the Python version.

MacOS

  1. Open Terminal and check if Python is pre-installed:
    python3 --version
  2. If not installed, use Homebrew (a package manager) to install it:
    brew install python
  3. Verify with:
    python3 --version

Linux

  1. Open your terminal and check for Python:
    python3 --version
  2. If it’s not there, use the package manager to install Python:
    • For Debian/Ubuntu:
      sudo apt update  
      sudo apt install python3
  3. Verify installation.

💻 Step 2: Setting Up a Code Editor

To write and run Python code efficiently, you need a good code editor. We recommend Visual Studio Code (VS Code).

Steps to Set Up VS Code

  1. Download VS Code from [code.visualstudio.com](https://code.visualstudio.com).
  2. Open VS Code and go to the Extensions Marketplace (on the left sidebar).
  3. Install the Python extension.
  4. Once done, you can write Python code, run it, and see results directly within VS Code!

Alternative Editors

  • IDLE: Comes built-in with Python.
  • Replit: Online editor, no installation required. Perfect for beginners.

🚀 Step 3: Writing Your First Python Program

Let’s write your very first program! 🎉

  1. Open your editor (VS Code, IDLE, or Replit).
  2. Create a new file and save it as hello.py.
  3. Write this simple code:
    print("Hello, World!")

What’s Happening Here?

  • print() is a built-in Python function that displays text on the screen.
  • "Hello, World!" is a string that we’re printing.

▶️ Step 4: Running Your Code

Here’s how you can run the hello.py program:

On VS Code

  1. Click the Run button at the top or press Ctrl + F5.
  2. You’ll see this output in the terminal:
    Hello, World!

Using Command Line or Terminal

  1. Navigate to the folder where hello.py is saved.
  2. Run this command:
    python hello.py
    Or on some systems:
    python3 hello.py
  3. The output will be:
    Hello, World!
    

🎯 Why This Matters

You’ve just written and executed your first Python program! This confirms that:

  • Python is successfully installed.
  • Your code editor is working correctly.
  • You’ve taken the first step into coding!

📝 Summary

In this section, you:

  1. Installed the latest version of Python.
  2. Set up a code editor (VS Code or alternatives).
  3. Wrote and ran your first program using Python.

Next up: Python Fundamentals → Variables, Data Types, and more! 🎯


🔗 Quick Links: