Python Course in 4 to 6 Weeks – Lesson 4: Variables & Data Types in Python

🧠 Python Course in 4 to 6 Weeks – Lesson 4: Variables & Data Types in Python

Welcome to Lesson 4 of our Python Course in 4 to 6 Weeks! 🎓 Today, we dive deep into one of the most essential concepts in any programming language — variables and data types. This lesson will teach you how Python stores and manages data, and how to use it effectively in your programs.



✅ What Are Variables?

Variables are like containers 🧺 that store data in a Python program. You can assign values to them, reuse them, and change them whenever needed.

name = "Amr"
age = 25
is_student = True

In the example above:

  • name stores a string (text)
  • age stores a number (integer)
  • is_student stores a boolean (True/False)

📦 Python Data Types Overview

Here are the most common data types in Python:

  • 🔤 String: text values like "Hello"
  • 🔢 Integer: whole numbers like 25
  • 💲 Float: decimal numbers like 3.14
  • 🔘 Boolean: True or False
  • 📜 List: multiple values in one variable – [1, 2, 3]
  • 📑 Dictionary: key-value pairs – {"name": "Amr", "age": 25}

🧪 Examples

Let's look at some examples of variables with different types:

username = "python_learner"     # string
score = 99                     # integer
average = 89.5                 # float
active = True                  # boolean
colors = ["red", "green"]      # list
user = {"name": "Amr", "id": 101}  # dictionary

📏 Type Checking

Use the type() function to check the type of a variable:

print(type(username))   # Output: 

⚠️ Common Mistakes

  • ❌ Mixing types: "3" + 3 will cause an error
  • ❌ Using undefined variables: always assign a value before using it
  • ❌ Wrong case sensitivity: Namename

🧠 Practice Exercise

Create a Python file called profile.py and write a program that:

  • Stores your name, age, and favorite color
  • Prints them using the print() function
  • Checks the type of each variable using type()

📥 Tools You'll Need

📌 Final Words

Variables and data types are the foundation of any programming language. With these tools, you can begin to build logic into your programs and store dynamic data. In the next lesson, we’ll explore how to use operators to perform calculations and comparisons in Python.

🔗 Coming Next:

Lesson 5: Operators in Python – Math, Logic, and More ➕➖➗

Post a Comment