Python Practice Set (Part 4): Variables & Data Types
- Anubhav Somani
- Sep 1
- 2 min read

In this practice set, we move beyond basic assignments to tackle problems that mirror real-world coding scenarios. You'll learn how to parse data from strings, manage ordered lists, understand the power of unchangeable tuples, and leverage sets to handle unique data. These exercises are designed to deepen your understanding of Python's versatile data types.
1. Extracting Product ID (String Slicing & Type Casting)
You are given a string product_info that contains a product ID: "SKU:A1B2-54321-XYZ". Your task is to extract only the numerical ID part ("54321") and convert it into an integer. Print the final integer ID.
Hint: Think about how you can split the string or find the position of specific characters.
2. Managing a Team Roster (List Methods: insert & pop)
You are managing a roster for a team. Start with a list of players: roster = ["Carol", "David"].
A new player, "Alice", has just become the team captain and needs to be at the front of the list. Use a list method to add her to the beginning.
The last player in the list, "David", has decided to leave the team. Remove him from the end of the list.
Print the final, updated roster.
3. Storing GPS Coordinates (Tuples)
A GPS coordinate consists of a latitude and a longitude, which should not change once recorded. Store the coordinates for a location (e.g., latitude 12.9716, longitude 77.5946) in a tuple named location_coords.
Print the entire tuple.
Access and print only the latitude value from the tuple.
Explain in a comment why a tuple is a better choice than a list for this data.
4. Finding Unique Tags (Sets)
You have a list of tags from several blog posts, and there are duplicates: tags_list = ["python", "data science", "coding", "python", "machine learning", "coding"]. Your task is to create a list that contains only the uniquetags. Print the final list of unique tags.
Hint: The set data type is perfect for automatically handling duplicates.
5. User Status Check (Booleans & the None Type)
Create a function get_user_status that takes a dictionary representing a user.
If the user dictionary has a key "is_active" with a value of True, the function should return True.
If the key "is_active" has a value of False, it should return False.
If the user dictionary is empty or doesn't have the "is_active" key, it should return None to indicate an unknown status.
Test your function with three different user dictionaries.
Comments