Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Errors, files and libraries · Lesson 18 of 25

    Modules and the standard library

    Import existing tools and organize files.

    8 minutes2 games

    A module is often a Python file. import math gives access to math.sqrt; from math import sqrt imports one name. The standard library ships with Python; external packages are installed in the project environment.

    Python
    import math
    from collections import Counter
    
    print(math.isqrt(81))
    counts = Counter("banana")
    print(counts["a"])
    print(sorted(counts.items()))
    ToolUse

    math

    Mathematics

    collections.Counter

    Count occurrences

    pathlib

    Filesystem paths

    json

    JSON encoding and decoding

    Important

    Avoid naming your file math.py or json.py; it may shadow the standard library module.

    Interview question

    Why use if __name__ == "__main__":?

    Complete the code

    Import math and print a square root.

     math
    print(math.(25))

    Exercise

    Use Counter and print the count of tea.

    Expected output: 2

    Python
    from collections import Counter
    orders = ["tea", "coffee", "tea"]
    

    Learn more from

    • Python documentationdocs.python.org
    • Real Python: further readingrealpython.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousHandling exceptionsNextReading and writing files
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.