Skip to content
VJ Classes

One place to learn science, commerce, arts, computers and life skills

Getting started

Why Python? The question behind programming

Key points

  • A program is a precise list of instructions; a programming language lets people write them in a readable form.
  • Python was created by Guido van Rossum and first released in 1991; this course uses Python 3.
  • Python is readable, comes with a large standard library and runs on Windows, macOS and Linux.
  • The interpreter runs your code directly; Python is slower than C or Java but much quicker to write.
  • Python is used in data analysis, machine learning, web development, automation and teaching.

Setting up and writing your first programs

Key points

  • Install Python 3 from python.org and check it with python –version (python3 on macOS and Linux).
  • IDLE is the simplest editor to start with; VS Code with the Python extension suits bigger programs.
  • print() displays values, and sep and end control spacing and line endings.
  • input() shows a prompt and returns what the user typed, always as a string.
  • Comments start with # and are ignored by Python.

The building blocks

Variables, data types, operators and f-strings

Key points

  • A variable is a name for a value; = stores a value, it does not test equality.
  • The basic types are int, float, str and bool, and type() shows the type of any value.
  • / always gives a float, // divides and rounds down, and % gives the remainder.
  • input() returns text, so convert it with int() or float() before calculating.
  • f-strings insert values into text, and formats such as .2f control decimal places.

Making decisions and repeating work

Key points

  • if, elif and else choose between blocks, and only the first true branch runs.
  • Use == to compare and = to store; indentation after a colon is part of Python’s grammar.
  • for loops walk through a sequence; range(a, b) stops just before b.
  • while loops repeat while a condition is True, so make sure it eventually becomes False.
  • break leaves a loop early, and continue jumps to the next pass.

Lists, tuples, dictionaries and sets

Key points

  • Lists are ordered and changeable; indexes start at 0, and -1 means the last item.
  • Tuples are like lists but cannot be changed, and they can be unpacked into variables.
  • Dictionaries map unique keys to values; get() avoids errors for missing keys.
  • Sets hold unique items and support union, intersection and difference.
  • Assigning a list to a new name does not copy it; use copy().

Writing real programs

Functions and modules

Key points

  • def creates a function; parameters receive values and return sends a result back.
  • Defining a function does not run it; calling it with arguments does.
  • Default values make parameters optional, and keyword arguments can be given in any order.
  • Variables created inside a function are local to that function.
  • import loads modules from the standard library, from your own files or from packages installed with pip.

Files and exceptions

Key points

  • open() with mode “r”, “w” or “a” reads, overwrites or appends, and with closes the file for you.
  • Use encoding=”utf-8” so that symbols such as ₹ are stored correctly.
  • An exception is a run-time error; try and except catch it so the program can respond.
  • finally always runs, and else runs only when there was no error.
  • Catch specific exceptions instead of using a bare except.

Classes, a mini project and next steps

Key points

  • A class is a blueprint; objects are instances, each with its own data.
  • The constructor stores the starting data, and self refers to the current object.
  • Methods are functions inside a class, called with a dot.
  • Real programs combine collections, loops, functions and classes, as the marks report does.
  • Keep improving by practising daily and building small projects of your own.

Important terms

  • A huge ecosystem
  • accumulator
  • Batteries included
  • break
  • call
  • choose
  • class
  • comment
  • comparison operators
  • condition
  • control flow
  • editor
  • elif
  • else
  • end
  • exceptions
  • f-strings
  • file
  • float(
  • for
  • free and open source
  • function
  • Guido van Rossum
  • high-level language
  • IDLE
  • indentation
  • input(
  • int(
  • interpreter
  • len(marks
  • list
  • Little ceremony
  • machine code
  • method
  • Missing quotes or brackets
  • module
  • operators
  • print(
  • program
  • programming language
  • prompt
  • Python 3
  • Python interpreter
  • python.org
  • range(
  • Readable code
  • released the first version in 1991
  • repeat
  • Runs everywhere
  • sep
  • shell
  • str(
  • string
  • sum(
  • type(
  • types
  • variables
  • VS Code
  • while
  • Wrong capital letters
Enrol to read the full lessons. This page is a summary. The lessons explain every point with examples, and enrolling also gives you the full notes PDF and your progress. See the course