Variables & Data Types Review
Back to basics — but faster and deeper
📖 Concept Recap
Python has four main data types you’ll use constantly:
- int — whole numbers:
42,-7,0 - float — decimal numbers:
3.14,-0.5,2.0 - str — text:
"hello",'Python' - bool — True or False (capital T/F, no quotes)
Variables are just labels that point to values. Type matters — Python treats "5" and 5 very differently. Use type() to check, and int(), float(), str() to convert.
👀 Worked Example
Study this code carefully before diving into the exercises:
Exercise 1 — Student Profile Variables
Fill in the blanks to create a complete student profile and print a formatted summary. Replace each ___ with a real value.
Exercise 2 — Product Inventory
Write code that stores a product name (str), price (float), quantity (int), and whether it’s in stock (bool). Then print:
- The total value (price × quantity)
- A sentence like: "Product Notebook: $5.99 each, 12 in stock."
f"Product {name}: ${price} each, {qty} in stock." to format the sentence.Exercise 3 — Type Conversion Puzzle
Python’s type conversion can fail in surprising ways. Your tasks:
- Try to convert the string
"3.14"to an integer directly usingint("3.14")— run it and see what happens. - Find the correct two-step method to convert
"3.14"to an integer. - Print the result and verify its type is
<class 'int'>.
int(float("3.14")). Think about why that works.Mini Project — Personal Profile Card Builder
Build a complete personal profile. Store: full name, age, city, major, GPA, year (Freshman/Sophomore/Junior/Senior), and is_full_time (bool). Then print a formatted profile card that looks like this:
f"{'Name:':<8} {name}" creates neat columns. Or just use spaces manually.✅ Lab 1 Complete!
You’ve reviewed variables, data types, type conversion, and f-string formatting. These are the building blocks of every Python program you’ll ever write.
Continue to Lab 2: Conditionals & Logic →