Python First

Introduction

2026-08-01

Abstract

Python logo Python First Wiki contains pages covering important Python topics. The order they could be read, depends on you requirements — each page is roughly chapter length. Towards the end of many pages, more advanced material may be discussed. Beginners can safely ignore advanced material in the short term — the content can be revisited when appropriate.

LICENSEWiki Content
The contents of this wiki, including images (unless otherwise stated), is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license. All source code, example snippets, and programs alike, excluding image sources, are licensed under the MIT No Attribution (MIT-0) license.

Things First

This wiki and associated repository contains several pages covering topics deemed appropriate for an introduction to the Python 3 scripting language. Example Python 3.14 and later code, will mostly be in the repository, while the wiki pages will contain references to them, and sometimes code extracts.

Focus

The primary focus of all this material, is Python language mastery, and writing scripts. No particular applications of Python are covered in any great depth. Python has its tail in too many pies to do them justice.

This wiki provides information for beginners to intermediate Python learners.

Prerequisites

Before starting to learn Python, it is important to have the necessary tools and to set realistic expectations. However, as the age of AI-assisted programming and learning is dawning, you may be able to take a non-traditional approach — but that's your prerogative.

     TL;DR:   os terminal shell python you

You

Theoretically it may be possible to learn a programming language without writing and running code, but that would be less than ideal, to say the least. Practice makes perfect and all that jazz.

Having some programming and/or scripting experience will be an advantage, but not strictly required. The same applies to command-line competency.

Python

To learn and use the Python language, a Python interpreter has to be installed. It should be available on your PATH. There are several implementations of the Python language, but this repository focuses solely on the reference implementation called CPython from its custodians at python.org. Alternative implementations are not covered.

Editor

Although any text editor will do, you should probably use a code editor. If you have no particular preference, just use VSCode; it is free and has good support for Python. Make sure code (the VSCode executable) is on your PATH, for an easier life.

If you are using GitHub's Codespaces, you can run VSCode in the browser, if you feel so inclined. Their ‘blank’ template has Python as well as a number of common third party packages installed, including IPython.

Shell

It is immaterial which operating system's CLI (character-based interface or shell) is used. However, examples include versions for Unix-like shells like bash and pwsh (PowerShell 7). The Windows Command Prompt (cmd.exe) is not covered.

From the command-line, at minimum, you should be able to:

Terminal

For a smooth experience and maximum pleasure, may we recommend at minimum a 256-colour terminal emulator, e.g., xterm, GNOME Terminal, Konsole; or third party. Modern examples include iTerm2 (macOS only), WezTerm, Kitty, Alacritty, and more.

On Windows, you will be well-served by Windows Terminal (wt.exe), though there are perfectly capable, and arguably better, third party terminal emulators available. The venerable PuTTY is still viable; plus WezTerm & Alacritty also run on Windows. The Windows Console (given relatively recent improvements) may work, but is not optimal.

OS

Any operating system supported by Python. When operating system specifics come up, we cover Linux, macOS, and Windows 11. WSL (Windows Subsystem for Linux) is Linux, so that will do as well.

Conventions

We use some arguably ‘unusual’ conventions and Unicode characters.

Typographical Conventions

Syntax elements are enclosed in single left & right angle quotation marks: (U+2039 & U+203A). As an example: ident is a syntax specifier that means identifier or name, and expr means expression. With that in hand, we can generalise the definition of a variable in Python:

     ident = expr

It can also appear as follows when we think it is more readable:

     ‹ident› = ‹expr›

But they will still be referenced in running text as identifier and expression. Either way, text between guillemets (··) are descriptions — you'll never type the text or guillemets.

A few characters or symbols are used as shorthand for common terms:

Scripts & Snippets

A complete Python script will always start with the following shebang (or hash-bang):

     #/usr/bin/env python3

Here is an example hyby.py (“high buy period pie”) complete script:

hyby.pySimple Python ‘Hello’ Script
#!/usr/bin/env python3
"""Hello/Goodbye, World Example"""

print("Hello, World!")
print("Goodbye.")

Code snippets (partial code), will not have a shebang line. If a code extract represents lines that belongs to a larger body of code, then we will indicate that with ···.

pyFirst print statement
···
print("Hello, World!")                #← from `hyby.py`(4).
···

Interactive Conventions

Interactive examples in a Python REPL (Read-Eval-Print-Loop), will appear in a code block, with the prompt indicated by ‘>>’; while continuation line prompts will start with ‘··’. Output will shown either in a comment if there is space on the same line causing the output ‘#▷…’, or on the following line or lines.

pythonPython REPL example
  • print("Hello, World!") #▷ Hello, World!
  • print( #← incomplete statement
       "Hello,\nWorld!") # that ends here.
    • Hello,
    • World!

In examples involving operating system shells, the prompt will be indicated with $>. The rest of the conventions are from above. Where appropriate, we will indicate whether a Linux shell or PowerShell is used with: sh or pwsh respectively; when command-lines are the same in both type of shells, we will not mention anything. For Command Prompt, we will use cmd.

command-lineExample command-lines for major shells

#━ sh (any POSIX shell like bash or zsh)

  • echo $PATH | tr ':' '\n'

#━ pwsh (or powershell)

  • $Env:PATH -split [IO.Path]::PathSeparator

#━ cmd (Command Prompt - cmd.exe)

  • for %P in ("%PATH:;=";"%") do @echo %P
  • for %P in ("%PATH:;=";"%") do @echo %~P

Terminology

Types & Classes

A type is a kind of classification or attribute applied to data values (also called objects). A type is like a plan of a house — it is not a house, but defines the characteristics of a house (like area, volume, number of rooms). A house build from the plan, would then exhibit these specified characteristics.

In a programming language, the type of an expression determines the storage space allocated to the value, and the operations that can be performed with that value (or object).

In object-oriented languages, a type can inherit characteristics and behaviours from a ‘parent’ type. When this relationship is apparent, we call the type a class instead. Python supports, but does not enforce, the use of object-oriented programming techniques… Python is a multi-paradigm language.

In Python, all types are classes. A default value for any type can be ‘constructed’ by using the type name as a function, leading to the term type functions.

Python is a dynamically typed language. This means that the types of expressions are only checked for validity relative the operation attempted while the program is being interpreted. This is common for scripting (interpreted) languages.

The type of an object therefore defines what operations you can perform on it, and how much storage space is required for the physical value of the object.

Expressions

An expression is a formal term that informally means ‘anything that represents a value’. This means a literal like 123 is an expression. An identifier that represents a value, (which is sometimes called a variable), is thus also an expression. Below, ident is an identifier (or label) that references the result of the expression: 123 + 234.

ident = 123 + 234

The result of any operator, is an expression, and so are its operands. An expression can therefore contain sub-expressions, separated by operators.

Operators in a complex expression are evaluated one-by-one, the order of which is determined by the precedence of operators in the expression, relative to the other operators. Parentheses can be used to force the order of evaluation. The final result of an arbitrarily complex expression is a single value (and thus an expression).

What is just as important to understand, is that: every expression has a value, as well as a type, which sound circular, because a value is an expression, but by value me mean the ‘raw computer value in memory’, which is a concrete sequence of bytes in the computer, whereas a type is an abstraction that governs the behaviour and operations on a value.

      expr   v   value
      expr   t   type

Think of an expression always having these two attributes. For example, the Python expression:

     2 + 3 * 5

Has the type int, and the value 17, or in more compact notation:

     2 + 3 * 5  t  int   v  17

If we apply parentheses, we can write:

     (2 + 3) * 5  t  int  v  25

The result of the expression is an int, simply because Python has rules that ensure that arithmetic operators + and \ with int operands, will produce an int result.

In summary: An expression is any combination of literals, variables, operators, and functions that can be evaluated to produce a single value. The order of evaluation is determined by the precedence of the operators and can be controlled using parentheses.

See Expressions for a more in-depth coverage of expressions and operators.

Literals

Literals are explicit constant values having a particular notation as defined by the language. For example: 123 is a decimal integer literal. The default notation is decimal, since we find that convenient as human beings. It is in an integer, because a decimal point is missing. It is a literal, because its value is apparent and constant.

Python has decided that this particular literal, has type: int. You can verify this by using the type() built-in function (which is also a type):

  • print( type(123) )
    • class int

Ignore the class part (all types are classes, so writing that is redundant, but technically correct). In IPython, the result will simply be int, which is what we care about.

Objects

Objects are values that have been created, having a programmer-specified type. We can say ‘an object is an instance of a class’, since all types in Python are class types — even simple types like int or bool.

The term object and value is really interchangeable in Python. But we use the term object more often when we want to emphasise the object-oriented nature of values. Because of this, an object in Python can have attributes (properties and methods).

The type of an object determines how it can interact with other objects, what operators can be applied to the object, the available properties that can be accessed, and the methods that can be called on the object.

Script vs Program

Python is a scripting language, which is why we often refer to a Python source file (with a .py extension) a script. But generally only when the source file represents a program.

A script is thus a Python source file that can be interpreted as a standalone program — generally a relatively simple program. A script can be executed by passing its name as argument to the python (or python3) interpreter. On Unix-like operating systems, it can made an executable by adding a shebang line, and setting its executable bit(s).

A program is a series of computer language statements that perform a required task or solve a particular problem. Whether a program is compiled or interpreted is immaterial. Either can automate tasks, process data, perform computations, interact with users, and produce output.

Module vs Package vs Library

A module is a .py file containing Python variable definitions, function definitions, class definitions and other statements. It is normally designed to be imported, and not run as a script, although it is possible for a .py file to be both useable as a module, and runnable as a script.

A package is a directory containing potentially any number of modules. It is distinguished by having a __init__.py file inside the directory.

A library is generally a collection of packages grouping together a number of related functionality and user-defined types.

These are loosely-defined terms. It is possible for a library to mean a single Python file. The context in which these terms are used should be taken into consideration.

Resources

A non-exhaustive list of categorised resource which may be useful is below.

DISCLAIMER
We do not claim suitability of these resources for your requirements. No affiliation with associated individuals, groups, companies, or ideologies, exists. We do not necessarily endorse, nor are we endorsed by, any of the belowmentioned. (WANL)

Python Distributions

Linux distributions are often packaged with an official CPython binary and standard libraries. Even if not, a python or python3 package should be available for installation. You can of course compile Python yourself — it is open source, after all.

Documentation

Well, guess we do endorse the following…

*PEPs cover a wide range of topics, including new features, changes to existing features, and informational documents.

Online Interpreters

Copyright © 2026 Codi Matters