Learning path

Full curriculum

Full curriculum

Unit content

Python programming

Python is a general-purpose programming language whose syntax emphasizes readable block structure and a relatively small amount of punctuation.

Values and variables

Python binds names with assignment:

name = "Ada"
count = 3
active = True

Its common built-in types include integers, floating-point numbers, strings, Boolean values, lists, tuples, dictionaries and sets.

Control flow

Indentation defines blocks:

if count > 0:
    print("items available")

for item in items:
    print(item)

Functions

Functions are defined with def:

def area(width, height):
    return width * height

Parameters are local names for the supplied arguments, and return sends a value back to the caller.

Collections

Lists store ordered values, dictionaries map keys to values and sets store distinct values:

numbers = [2, 4, 6]
user = {"name": "Ada", "active": True}
tags = {"math", "code"}

Modules

Definitions can be organized into modules and imported:

import math
radius = math.sqrt(25)

Python provides one concrete syntax for the language-independent programming ideas already developed: expressions, control flow, functions, collections, modules and input/output.