Skip to contentSkip to navigation

Module 5 of 6, Practical Python

Standard Library Tools

Match text patterns, work with dates and times, and make random choices.

module checksSign in to track

  • Lessons complete-, not done
  • Lesson quizzes taken-, not done
  • Module Labs passed-, not done
  • Module exam passed at 80%-, not done
lessons
3
quiz questions
36
reading time
24 min
exam length
15 Q
coding exercises
6

Lessons

  1. Regular ExpressionsFind and check patterns in text with the re module: character classes, repetition and anchors, search versus fullmatch, findall, groups and sub, always written as raw strings. 8 min 12 questions
  2. Dates and TimesWork with calendars and clocks: create dates and datetimes, do arithmetic with timedelta, compare them, and turn them into text and back with strftime, strptime and ISO format. 8 min 12 questions
  3. Random Numbers and SecretsAdd chance to programs with the random module: random numbers, choices, samples and shuffles, repeatable results with seed, and the secrets module for passwords and tokens. 8 min 12 questions

Lab: write it yourself

Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (3 exercises)

All module exercises

The Lab needs an account. Sign in or create a free ID to run these exercises.

Lab 1: Extract digits

Sign-in required

Use re.findall(r"\d+", "Item 42 costs 150 taka"). Print the extracted list of digit strings: ['42', '150'].

Sign in to practise

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.

Lab 2: Days difference

Sign-in required

Calculate the days between date(2026, 1, 1) and date(2026, 1, 10). Print: Days: 9.

Sign in to practise

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.

Lab 3: Sample without replacement

Sign-in required

Set random.seed(5). Sample 2 items from ['cat', 'dog', 'bird', 'fish'] using random.sample(). Print: Sampled 2 items: True.

Sign in to practise

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.

References & Further Reading

Related entries from PyLabs's own reference library.

  • round() (Round a number to a chosen number of digits.)
  • replace() (Replace matching text with new text.)