Skip to main content

Variables & Data Types 🚀

Variables are named storage locations in memory that hold a value which can change during program execution. In Python, a variable is created the moment you assign a value (x = 5) — no type declaration is required, and the same variable can later hold a different type (x = "hello"). Python's core data types are grouped into Numbers (int, float, complex), Text (str), Boolean (True / False), Sequence (list, tuple, range), Mapping (dict), Set (set, frozenset), and the special None type. Understanding variables and data types is the foundation of every Python program — from "Hello World" to machine-learning pipelines.

Mentor's Note: Variables are the "memory" of your program. Without them, your code would forget everything as soon as it happened! 💡


🌟 The Scenario: The Warehouse 📦

Imagine you are managing a huge warehouse.

  • The Logic: You have thousands of items. To stay organized, you put items into Boxes and stick a Label on them (like "Toys" or "Shoes"). 📦
  • The Result: When you need the toys, you just look for the label "Toys." In Python, the Label is the Variable Name, and the Item inside is the Value. ✅

📖 Concept Explanation

1. Variables

A variable is a name that refers to a location in computer memory.

2. Rules for Naming Labels 🏷️

  • Must start with a letter or underscore _.
  • Cannot start with a number.
  • Can only contain A-z, 0-9, and _.
  • Case-sensitive (price is different from Price).

3. Dynamic Typing (The "Smart Box")

In Python, boxes are smart. You don't have to decide if a box is only for "Shoes" forever. Today it can hold a number 5, and tomorrow it can hold the word "Hello".


🎨 Visual Logic: The Data Type Tree


💻 Implementation: Variable Lab

# 🛒 Scenario: Stocking the Warehouse
# 🚀 Action: Creating different types of data

# Integer (Whole number) 🔢
box_count = 100

# Float (Decimal) 💲
price = 19.99

# String (Text) 📛
label = "Super Gadget"

# Boolean (True/False) ✅
is_in_stock = True

# List (Ordered items) 🛍️
colors = ["Red", "Blue", "Green"]

# Dictionary (Label: Value pairs) 📖
stats = {"weight": "2kg", "height": "10cm"}

print(f"Item: {label}, Total Boxes: {box_count}")

📊 Sample Dry Run

StepInstructionVariable NameTypeValue
1age = 25ageint25 📦
2age = "Old"agestr"Old" 🔄

📉 Technical Analysis

  • Memory: Python uses References. When you create x = 5, Python creates an object 5 in memory and points x to it.
  • Mutability: Some types (like list) can be changed inside their box. Others (like tuple or str) cannot—you have to replace the whole box!

🎯 Practice Lab 🧪

Task: Store Profile

Task: Create variables for a store: store_name, rating (decimal), and is_open. Print them all in a single sentence. Hint: Use an f-string: f"Welcome to {store_name}!" 💡


📚 Best Practices

  • Use Snake Case: Always name variables with underscores (e.g., user_account, not userAccount).
  • Meaningful Names: Use price_per_item, not p.

💡 Pro Tip: "Before software can be reusable it first has to be usable." - Ralph Johnson



← Back: Keywords | Next: Numbers & Casting →

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir