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
- 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
- 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
- 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)
The Lab needs an account. Sign in or create a free ID to run these exercises.
Lab 1: Extract digits
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
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
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.