Learn Python programming from scratch with step-by-step tutorials, clear code examples, and practical coding exercises with full solutions. Designed for beginners and intermediate learners building real-world skills.
Python Basics · Capstone Build a Study Sprint Tracker Bring together the skills from this track by writing a small program that records study time, calculates a summary, and gives the learner a useful message. You’ll combine: strings, variables, input, conditions, loops, lists, dictionaries, and functions. Plan the program Ask for the learner’s name and clean up the text. Ask how many days to track and validate that the number is positive. Use a loop to collect each day’s study minutes in a list. Use a function to calculate totals and return a summary dictionary. Use a condition to give an encouraging next-step message. Warm-up exercises Write a function that receives a list of minutes and returns the total and average. Write an if/else statement that prints "Steady progress!" when an average is at least 25 minutes and "Try a short ses...
Python Intermediate · Lesson 19 Iterators and Generators Python can produce values one at a time instead of building a large list first. Iterators and generators are useful for processing files, records, or calculated sequences in a steady stream. By the end, you can: use iter() and next() , write a generator function with yield , create a generator expression, and process a stream of CSV rows without loading the whole file into memory. One-pass reminder: a generator is usually consumed as you loop over it. If you need to process the same values multiple times, create a new generator or deliberately save the values in a collection. 1. Iterable versus iterator An iterable can provide an iterator. Lists, strings, and dictionaries are common iterables. An iterator produces the next value when asked and remembers where it is in the sequence. topics = ["functions", "files", ...
Python Basics · Lesson 07 Working with Text and Strings A string is text in a Python program. You can clean it, search through it, split it into pieces, and combine those pieces to make useful output. By the end, you can: use common string methods, select characters and slices, split and join text, and keep in mind that string methods return new strings. 1. Strings are sequences of characters A string is written inside quotes. Like list items, its characters have indexes that start at 0. language = "Python" print(language[0]) print(language[1:4]) The first line displays P . The slice [1:4] starts at index 1 and stops before index 4, so the second line displays yth . 2. Clean and change text with methods String methods perform common text tasks. strip() removes extra spaces from the ends, while lower() and upper() change letter case. raw_name = " Sam Lee ...