Learn by reading through in order

Python Basics Wrap-Up Problems — Put What You Learned into Code

Three Python basics wrap-up problems: format "1995-08-21" using split and int(), classify submissions with set operations, and compare assignment vs copy() on mutable types.

Problem 1: Parse a date string and reformat it

Take a birthday string birthday and turn it into a more readable format for humans. Split the string, convert each part to an integer with int(), and stitch the result back together with an f-string.

How to break a string apart and convert it to numbers
"1995-08-21"original string["1995", "08", "21"]result of split("-")1995 / 8 / 21converted with int()"August 21, 1995"formatted with f-stringsplitintf-string
Split into a 3-element list, then int() to drop the leading zeros. Finally, build the result with an f-string.

Take the string birthday = "1995-08-21" and build a readable date string in the format August 21, 1995.

Make sure the day doesn't keep its leading zero (08 should appear as 8).

Python Editor

Run code to see output

Problem 2: Compare submissions with set operations

You want to compare who submitted assignment A and who submitted assignment B. With set operations, you can pull out the people who submitted both and the people who only submitted one of them in a single line each.

How & and ^ produce different results from set_a and set_b
set_a{Alice, Bob, Carol, Dave}set_b{Bob, Carol, Eve}{Bob, Carol}{Alice, Dave, Eve}set_a & set_bset_a ^ set_b
Both sets feed into the same operation; the arrow label tells you which operation, and the arrow tip shows what comes out.

Submitters for assignment A are submitted_a = ["Alice", "Bob", "Carol", "Dave"], and submitters for assignment B are submitted_b = ["Bob", "Carol", "Eve"].

From these two lists, find the people who submitted both and the people who submitted only one of them, then print each result as a list sorted alphabetically.

Python Editor

Run code to see output

Problem 3: See how mutability really works

You think you copied a list to a new variable, but the two are actually pointing at the same object — that's the classic gotcha with mutable values in Python. Try changing the original after using copy() and after a plain assignment, and watch what happens.

Assignment shares a reference; copy() makes a new object
group_a = students(assignment)group_b = students.copy()(copy)Same list, two namesstudents → [A, B]group_a → [A, B]Separate listgroup_b → [A, B]After append("Carol")students → [A, B, Carol]group_a → [A, B, Carol]Unaffected by appendgroup_b stays [A, B]sharedindependent
Assignment just gives the same list a second name. Change the original later and you'll see the change through both names. copy() builds a separate list, so it's untouched.

This one is about observing the difference between assignment and copy(). Build a list students with two names, then make two more variables — one assigned directly from students (group_a) and one made with copy() (group_b).

After that, append a third student to students and print students, group_a, and group_b in order to see whether the new student shows up in each.

Python Editor

Run code to see output

Nice work getting through this

That wraps up Python Basics. You've covered variables and data types, how to choose between strings, lists, dicts, and sets, and assignment vs. copy() for mutable values — pretty much every tool you need to handle data day-to-day. From printing simple values to combining types and transforming data, you can now write and run those programs yourself.

The next chapter, Python Syntax, brings in the control flow you use to actually drive a program: if, for, while, plus function definitions with def / lambda, list comprehensions, decorators, generators, and exception handling with try / except.