Chapter 1

Getting Started with Python

Learn how programs turn a task into precise instructions and how Python runs those instructions. You will run small programs, read their output and errors, and make controlled changes without needing previous programming experience.

Programming begins with a task, a method for completing it, and instructions that express that method. Python is a programming language: a way to write those instructions so a compatible runtime can execute them. In machine learning, this lets us turn an idea or calculation into a program whose intermediate values and final result we can inspect.

This chapter begins in the browser, so you can run the first examples without installing anything. It then shows how to check Python on your computer, save code in a script, run that script from a terminal, and use an interactive Python session for quick questions.

The final lessons separate code from output, introduce simple error messages, and develop a useful programming habit: change one thing, run the program again, and compare the result with what you expected. That habit will support every later Python chapter.

After this chapter

  • Explain the roles of a task, algorithm, source code, and runtime.
  • Identify the input, processing, and output of a small program.
  • Run a small Python script.
  • Tell code apart from output.
  • Use an interactive session for tiny checks.
  • Read simple errors as debugging information.
  • Edit one line, rerun, and explain the changed output.

Your learning

Lessons

  1. 01
    Programming and Python

    Understand programs, algorithms, input, processing, output, source code, and the role of a Python runtime.

    1 exercise
  2. 02
    How Python Reads and Runs Code

    See how Python follows exact instructions, evaluates expressions, and displays output.

    1 exercise
  3. 03
    Checking and Installing Python

    Check for a supported Python interpreter and install it safely when needed.

    2 exercises
  4. 04
    Scripts and the Terminal

    Create a Python script, locate it from the terminal, run it, and diagnose common folder and filename problems.

    2 exercises
  5. 05
    Using the Interactive Python Prompt

    Use the Python prompt for quick checks, retained values, and small errors, then leave the session safely.

    3 exercises
  6. 06
    Reading Python Output and Error Messages

    Compare expected and actual output, then read a short Python traceback to locate and understand an error.

    3 exercises
  7. 07
    Editing, Commenting, and Rerunning Python Code

    Edit and rerun a Python program, inspect intermediate values, and write comments that explain useful intent.

    3 exercises

Review and practice

  1. Review

    Review how to run Python, interpret results, read tracebacks, use comments, and make controlled changes.

  2. Exercises

    Practice reading Python results, diagnosing errors, interpreting comments, and making controlled edits in runnable programs.