Getting Started with Python

Welcome to your Python journey! Before we dive into the language, let’s set up your environment and write your very first Python program.


Setting Up Your Python Environment

Install Python on Your Computer

  1. Download Python:
    Visit the official Python website and download the latest version.

  2. Install Python:
    Follow the installation instructions for your operating system:

    • Windows: Run the installer and ensure the "Add Python to PATH" option is checked.
    • Mac/Linux: Python is pre-installed on most systems. Verify by running python3 --version in your terminal.
  3. Verify Installation:
    Open a terminal or command prompt and type:

    python --version
    

    or

    python3 --version
    
Warning

If Python isn't recognized, ensure it's added to your system's PATH variable.


Writing Your First Python Program

Step 1: Open Your Editor or IDE

Use a code editor like VS Code, PyCharm, or Python’s built-in IDLE.

Step 2: Write Your Code

Create a new file called hello.py and write the following:

# This is your first Python program
print("Hello, Python World!")

Step 3: Run Your Program

  • Command Line:
    Open a terminal in the file's directory and type:

    python hello.py
    

    or

    python3 hello.py
    
  • IDE:
    Most IDEs have a "Run" button to execute the code.

Info

The print function is used to display text or output in Python. In this case, it prints "Hello, Python World!" to the console.


Exploring the Python Interactive Shell

Python provides an interactive shell to run code line by line.

Open the Python Shell

  • Type python or python3 in your terminal and press Enter.
  • You’ll see a prompt like:
    >>>
    

Run Python Code Interactively

Try this:

print("Hello from the Python Shell!")
Deep Dive

Why Use the Python Shell?

The interactive shell is great for:

  • Testing small code snippets.
  • Exploring Python functions and libraries.
  • Debugging and experimenting.

Use the shell to quickly test ideas without creating a new file.

Task

Practice: Write and Run Your First Python Program

Objective: Create a Python script that prints your name and calculates a basic mathematical operation.

  1. Create a File:
    Name the file intro.py.

  2. Write the Code:
    Add the following lines:

    # Display your name
    print("Hello, my name is [Your Name].")
    
    # Perform a simple calculation
    print("The result of 25 + 30 is:", 25 + 30)
    
  3. Run the Script:
    Execute the file using your preferred method (terminal or IDE).

  4. Experiment:
    Modify the script to include:

    • Subtraction, multiplication, and division.
    • Your favorite quote or a fun fact about Python.

Copyright © 2025 Devship. All rights reserved.

Made by imParth