PNL Learn

Modules and the Standard Library

Import, organize and lean on Python's batteries-included library.

Working developers rarely write everything from scratch: they import it. You will learn how imports, modules and packages really work (where Python looks, what it caches, what the platform module reports), then put the standard library to work the way teams do: Counter and defaultdict for counting and grouping, datetime for real date arithmetic, regular expressions for pulling data out of text, and math, random, statistics and functools for everyday number crunching. The course ends with realistic tools: a log report, a subscription renewal calculator, a word ladder solver and a weekly event scheduler.

IntermediatePython7 lessons91 exercisesAbout 6.5 h
Create a free account

What you will learn

  • Imports and modules
  • Packages and sys.path
  • platform, os and pathlib
  • collections
  • datetime
  • Regular expressions
  • math and statistics
  • functools

Lessons

  1. 1

    Imports and Modules

    Pull in code with import, from and as, avoid star imports, ask the platform module what you are running on, see what a module really is, guard scripts with __name__, and dodge the shadowing trap.

    17 exercises

  2. 2

    Packages and the Import System

    Group modules into packages, import between them, mark what is public, see where Python looks for modules and how it caches them, and use os, sys and pathlib for environment and paths.

    14 exercises

  3. 3

    collections

    Count with Counter, group with defaultdict, name your tuples with namedtuple and keep a rolling window or a queue with deque.

    14 exercises

  4. 4

    Dates and Times

    Build dates, do real date arithmetic with timedelta, format and parse with strftime and strptime, and store moments in UTC with aware datetimes.

    13 exercises

  5. 5

    Regular Expressions

    Find, validate, extract and rewrite text with re: search versus match versus fullmatch, classes and anchors, greedy quantifiers, groups and re.sub.

    14 exercises

  6. 6

    math, random, statistics and functools

    Round, truncate and compare floats properly with math, make randomness reproducible, summarize numbers with statistics, and reach for functools and operator instead of writing helpers by hand.

    12 exercises

  7. 7

    Putting It Together

    Combine re, collections, datetime and calendar into realistic tools: a log report, a subscription renewal calculator, a word ladder solver and a weekly event scheduler.

    7 exercises

How you practice

You practice in the browser and every exercise gives you feedback right away. This course uses these formats:

  • Code exercise: 35
  • Predict the output: 19
  • Fix the bug: 15
  • Fill in the blank: 8
  • Type the answer: 5
  • Match the pairs: 4
  • Multiple choice: 2
  • Spot the bug: 1
  • Select all that apply: 1
  • Reorder lines: 1

Aligned to

PCAP-31-03Python InstituteSource
  • Modules and Packages
    • 1.1Import and use modules and packages
    • 1.2Perform evaluations using the math module
    • 1.3Generate random values using the random module
    • 1.4Discover host platform properties using the platform module
    • 1.5Create and use user-defined modules and packages
CS2023ACM / IEEE-CS / AAAISource
  • Software Development Fundamentals
    • SDF-FundamentalsFundamental Programming Concepts and Practices

Proto Node Labs is not affiliated with or endorsed by Python Institute and ACM / IEEE-CS / AAAI. Exam names are trademarks of their owners.